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!

