the command after "if" not work after awhile
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
mohammad gudarzi
am 23 Mai 2019
Kommentiert: mohammad gudarzi
am 23 Mai 2019
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 Kommentare
Geoff Hayes
am 23 Mai 2019
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?
Akzeptierte Antwort
the cyclist
am 23 Mai 2019
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].
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Function Creation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!