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!