필터 지우기
필터 지우기

Plotting error message

조회 수: 3 (최근 30일)
old_user_rat
old_user_rat 2012년 4월 6일
Hi,
I am running this code:
y1 = 0:.01:1;
for y2=0:1/10:1;
l=1+y2*10;
t(:,l) = y1.^3./12 + (y1.^2.*y2)/4 - y1.^2./2 + (y1.*y2.^2)/4 - y1.*y2 + y1
- (7.*y2.^3)/12 + (3.*y2.^2)/2 - y2;
end
plot(y1,t)
and get this error:
Subscript indices must either be real positive integers or logicals.
However when I run this code:
y1 = 0:.01:1;
for y2=0:1/10:0.5;
l=1+y2*10;
t(:,l) = y1.^3./12 + (y1.^2.*y2)/4 - y1.^2./2 + (y1.*y2.^2)/4 - y1.*y2 + y1
- (7.*y2.^3)/12 + (3.*y2.^2)/2 - y2;
end
plot(y1,t)
There is no problem! (only difference is the 3rd line)
Can someone explain why I cannot do the first one?
Best,
David

채택된 답변

Wayne King
Wayne King 2012년 4월 6일
You have the line:
l=1+y2*10;
and then you try to use that to index the columns of t(), but you actually have an index not equal to an integer
l =
7.000000000000001
I'm not sure why you're trying to do here, but how about
l=1+round(y2*10);
That should enable your loop to run and produce your plot.

추가 답변 (2개)

Walter Roberson
Walter Roberson 2012년 4월 6일

old_user_rat
old_user_rat 2012년 4월 6일
Thanks guys, that's clear now

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by