Subscript indices must either be real positive integers or logicals.

1 回表示 (過去 30 日間)
Martin
Martin 2014 年 10 月 28 日
回答済み: Martin 2014 年 10 月 28 日
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

採用された回答

Adam
Adam 2014 年 10 月 28 日
編集済み: Adam 2014 年 10 月 28 日
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.

その他の回答 (2 件)

yonatan gerufi
yonatan gerufi 2014 年 10 月 28 日
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 件のコメント
Martin
Martin 2014 年 10 月 28 日
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.

サインインしてコメントする。


Martin
Martin 2014 年 10 月 28 日
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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by