Subscript indices must either be real positive integers or logicals.

1 view (last 30 days)
Subscript indices must either be real positive integers or logicals.
Error in ==> Vinci_DLR at 175 alpha_amb = alpha(Nu_amb, la_amb, do, 1);
My alpha-calculation is a very simple function within my m-file and works without error in a single run. For iterative approach I nested it in a while-loop and I got the error above at second iteration. Why? I have similar other functions in this while loop where this problem does not occur.
Examples:
Ra = Raleigh(dT_amb, L, amb_type); % Raleighnr. for ambient convection
Nu_amb = Nusselt(0, Pr_amb, Ra, 0, 0, 2) % Nusselt number

Accepted Answer

Adam
Adam on 28 Oct 2014
Edited: Adam on 28 Oct 2014
I assume alpha is meant to be a function?
Are you also naming a variable alpha within the same workspace? If so then that variable will take precedence and the line you quote will be interpreted as trying to index into the variable rather than pass arguments to the function.
On a similar note, 'alpha' is actually also the name of a builtin Matlab function. It may not be one you require to use within your code, but it is good practice generally to avoid stamping on names of builtin functions unless you actually want to over-ride them.
You can type
which alpha
or
which alpha -all
to find out if a name already exists as function or as a variable too.

More Answers (2)

yonatan gerufi
yonatan gerufi on 28 Oct 2014
your example is very hard to understand.
you should use debug to catch the error.
try this method:
try
your code..
catch
display('error') - put break point here!
end
now, when it stops see the value of indices.
good luck!
  1 Comment
Martin
Martin on 28 Oct 2014
Hi Yonatan, thanks for your help. These are the values of the error:
??? Attempted to access alpha(19897.4,0.105,0.1082,1); index must be a positive integer or logical.
But the first loop has similar values and works without error, same as above mentioned functions.

Sign in to comment.


Martin
Martin on 28 Oct 2014
Hello Adam,
thanks a lot, I didn´t know that "alpha" is an already built-in function. After renaming my function the code worked perfectly :-).
Best regards,
Martin

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!