Plotting results in array of a while loop
Mostra commenti meno recenti
Hello,
I want to iteratively plot the results of my while loop, however, I end up with a blank graph or an error.
Here is the code:
Vlow=350;
fs=100000;
n=0.56;
Lk=41.98*0.000001;
P=10000;
Vhigh=900;
C=0;
i=0;
s=poly(0,"s");
while Vlow < 450
Polynome=((P*Lk*n*fs)/(Vhigh*Vlow))-s+s^2;
solution=roots(Polynome);
out = solution(solution<0.35 & solution>0.129);
I1=(1/(2*Lk*fs))*(2*(Vlow/n)*out+Vhigh-(Vlow/n));
I2=(1/(2*Lk*fs))*(2*Vhigh*out-Vhigh+(Vlow/n));
if I1 > I2 then
C= I1;
else
C=I2;
end
Y(i)=C;
X(i)=Vlow+20;
i=i+1;
end
plot(X,Y);
Any help would be greatly appreciated,
Thank you
8 Commenti
Geoff Hayes
il 22 Giu 2020
Hicham - please copy and paste the full error message to your question. Is the problem with poly or something else?
Adam Danz
il 22 Giu 2020
@Hicham Lhachimi, just to be clear, the code you shared does not generate an error message? Your question states that it does. If it does, we would need the entire error message.
What is the function "ploy"? When I run your code, an error message is generated.
Adam Danz
il 22 Giu 2020
Do you mean "ploy" is a typo and it should read "plot" or do you mean you have a custom function named ploy that we do not know about?
When I replace ploy with plot, there is a blue square marker printed on the plot at (1,0).
Hicham Lhachimi
il 22 Giu 2020
Adam Danz
il 22 Giu 2020
Sorry for the confusion. I meant poly.
Matlab has a fuction poly but it only has 1 input. In this line of your code,
s=poly(0,"s");
you have 2 inputs which would cause an error. The syntax you're using looks like you meant to use plot instead of poly.
Hicham Lhachimi
il 22 Giu 2020
Modificato: Hicham Lhachimi
il 22 Giu 2020
Image Analyst
il 22 Giu 2020
So s is this:
s =
1 -1 0.0746311111111111
which is a 1-by-3 vector, so it throws an error when you do this:
Polynome=((P*Lk*n*fs)/(Vhigh*Vlow))-s+s^2;
Were you expecting s to be a scalar instead of a 1-by-3 vector?
Hicham Lhachimi
il 22 Giu 2020
Modificato: Hicham Lhachimi
il 22 Giu 2020
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

