the command after "if" not work after awhile
1 次查看(过去 30 天)
显示 更早的评论
the "counter"=1 at start, the command under if work until t==8 but after that it's looklike "if" not working beside that "t" continue untill 200.
thanks
if t==(1*counter)
filename = 'y.xlsx';
filename1= 'V.xlsx';
filename2= 'Q.xlsx';
A=double(yp);
C=double(vp);
D=double(Qp);
for i=1:16
maty(counter,i)=A(1,i);
matQ(counter,i)=D(1,i);
matv(counter,i)=C(1,i);
my{counter,i}=[A(1,i)];
mv{counter,i}=[C(1,i)];
mq{counter,i}=[D(1,i)];
end
counter=counter+1;
end
4 个评论
Geoff Hayes
2019-5-23
What are you expecting to happen with this code?
if t==0:1:200
plot(X0,yp)
end
Do you really mean to compare t to an array of values from 0-200?
采纳的回答
the cyclist
2019-5-23
My best guess here is that you are running up against the limitations of floating point computation. For example, try putting this expression into MATLAB:
6*0.01 == (0.01+0.01+0.01+0.01+0.01+0.01)
You will find that the result is false (logical 0). This is probably unexpected by you.
Then try
6*0.01 - (0.01+0.01+0.01+0.01+0.01+0.01)
and you will see that the result is a number of order 1.e-18 (very tiny but not zero).
I suggest that you read this documentation page about floating point representation. There are also many, many answers here that talk about this issue. Be aware that this is not some kind of MATLAB error.
I also happened to notice that you have this line in your code:
if t==0:1:200
...
end
I'm not sure what you are expecting to happen there, but you will only enter that loop is t is equal to the vector [0 1 2 ... 199 200].
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!