Index exceeds matrix dimensions error message
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm trying to use a while loop to create vectors so that I can plot the values but I keep getting the "Index exceeds matrix dimensions" error message. Any help is appreciated. This is my code:
figure(1)
z1=.6;
z2=.85;
z3=1.23;
V=sqrt(2*9.81*(z3-z1));
i=1;
t=0;
%%
while z3(i) >=0
x(i)=t*V;
Z3(i)=z3-.5*9.81*(t^2);
t=t+.25;
i=i+1;
end
댓글 수: 0
답변 (1개)
KALYAN ACHARJYA
2019년 11월 13일
편집: KALYAN ACHARJYA
2019년 11월 13일
Yoi defined z3 as scalar, but in the while loop you trying acess it as vectors
#Defined here
z3=1.23;
#
while z3(i)>=0
%...
end
Here waht does z3(i) means. In Matlab z3(i)
%.................................................................^ means array indexing
See the following example
>> Z3=4;
>> Z3(1)
ans =
4
>> Z3(2)
Index exceeds matrix dimensions.
>>
When "i" incremented within while loop, in the next iteration, how does z3 gets the value when i is greater than "i", like z3(2),z4(3)..so on.
Hope it helps, any issue let me know.
댓글 수: 2
KALYAN ACHARJYA
2019년 11월 13일
You have to figure out, it seems simple
z1=.6;
z2=.85;
z3=1.23;
V=sqrt(2*9.81*(z3-z1));
i=1;
t=0;
while z3>=0
x(i)=t*V;
z3=z3-0.5*9.81*(t^2);
t=t+.25;
i=i+1;
end
Do the proper notbook calculation and show me, so that I can help you Matlab implementation.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!