Why this error is coming in my code?
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
zeros(1500,2);
for j=1:3
zeros(j,1)=randi([1,5],1,1);
zeros(j,2)=randi([1,5],1,1);
end
ones(1500,2);k=0;
if true
% code
end
while k<365
ones(k,1) = 1*2*zeros(k,1);% i have assumed velocity in x direction to be 2m/d.
ones(k,2) = 1*1*zeros(k,2);% velocity in y direction is assumed to be 1m/d.
end
Subscript indices must either be real positive integers or logicals.
Error in oncemore (line 8) ones(k,1) = 1*2*zeros(k,1);% i have assumed velocity in x direction to be 2m/d.
0 件のコメント
回答 (1 件)
Azzi Abdelmalek
2015 年 6 月 26 日
There are many problems in your code The first line:
zeros(1500,2);
What this line means? then after you wrote
zeros(j,1)=randi([1,5],1,1)
Which will destroy the built-in function zeros
3 件のコメント
anchal garg
2015 年 6 月 26 日
編集済み: anchal garg
2015 年 6 月 26 日
Azzi Abdelmalek
2015 年 6 月 26 日
編集済み: Azzi Abdelmalek
2015 年 6 月 26 日
m=4
n=2
a=randi(5,m,n)
@anchal, assuming it's the first run of your script, the line
zeros(1500,2);
means Create a matrix of zeros of size 1500x2 and because I don't store it anywhere, immediately forget about it. Basically, it does nothing but waste time.
You then go on to create a variable call zeros which will prevent the built-in matlab zeros function from working.
You then do the exact same thing with ones. Invoke the function, but do nothing with the output and then prevent the function from working again (until you clear your variables)
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!