Info

この質問は閉じられています。 編集または回答するには再度開いてください。

While running program it shows an error Subscript indices must either be real positive integers or logicals.

1 回表示 (過去 30 日間)
balaji
balaji 2014 年 10 月 12 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
The Code is here
for i=1:3
for j=1:5
x(i,j) = round(y(i,j)+(unifrnd(-1,1)*(y(2,j)-y(3,j))));
end
end
Please help me to overcome the above error
  13 件のコメント
Jan
Jan 2014 年 10 月 13 日
編集済み: Jan 2014 年 10 月 13 日
Please, balaji, format your code such that it is readable. Look at the "{} Code" button.
Lines like "x;" are meaningless and increase the level of confusion only.
"diff" is the name of the function. Do not cover it by using it as a name of a variable.
Please add a complete copy of the error message, most of all the line, which causes the error. And take the chance to let the debugger locate the problem for you, as explained in my answer. This is much smarter than asking the members of the forum to use the debugger to do the same for you.
The posted code runs without any error on my Matlab. Please copy it into a function (not a script!) to check, if you have redefined a symbol, e.g. "round".
Guillaume
Guillaume 2014 年 10 月 13 日
Balaji, please edit your comment and use the {} code button to format your code.
As it is now, your y is a 1x220 vector, yet you try to access y(i,j) with i > 1. That is of course giving me an error (but not the one you mentioned).
Additionally, if all you want to generate are integers, you can use randi.
Finally, you seem to be using a variable named diff. Rename it to something else as it is shadowing matlab's diff function.

回答 (1 件)

Jan
Jan 2014 年 10 月 12 日
The debugger is the perfect tool to investigte such problems. Type this in the command line:
dbstop if error
Then run your code again until Matlab stops, when the error occurres. Then evaluate the current line in pieces until you find out, which expression causes the error.
Using the debugger locally is much more efficient than asking the forum.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by