Plotting results in array of a while loop
Afficher commentaires plus anciens
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 commentaires
Geoff Hayes
le 22 Juin 2020
Hicham - please copy and paste the full error message to your question. Is the problem with poly or something else?
Adam Danz
le 22 Juin 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
le 22 Juin 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
le 22 Juin 2020
Adam Danz
le 22 Juin 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
le 22 Juin 2020
Modifié(e) : Hicham Lhachimi
le 22 Juin 2020
Image Analyst
le 22 Juin 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
le 22 Juin 2020
Modifié(e) : Hicham Lhachimi
le 22 Juin 2020
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

