Plotting results in array of a while loop
显示 更早的评论
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 个评论
Geoff Hayes
2020-6-22
Hicham - please copy and paste the full error message to your question. Is the problem with poly or something else?
Adam Danz
2020-6-22
@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
2020-6-22
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
2020-6-22
Adam Danz
2020-6-22
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
2020-6-22
编辑:Hicham Lhachimi
2020-6-22
Image Analyst
2020-6-22
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
2020-6-22
编辑:Hicham Lhachimi
2020-6-22
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

