Cannot Plot in the Desired interval, What am i doing wrong here?

theta(:,1) = [0:360]';
Ac = 5;
k = 2000;
m = 0.001;
RPM = 1500;
if theta(theta(:,1)>110) && theta(theta(:,1)<170)
x = (Ac/k)*(1+sin(sqrt(k/m).*(theta/6*RPM)-(pi/2)));
else
x = 0;
end
plot(theta,x);
I want to plot for theta varying from 0 to 360, but only desire to have x between theta>110 and <170
But its returning me errors
I have tried & insted of && too
Can you suggest me a modification
Thank you

 채택된 답변

madhan ravi
madhan ravi 2020년 6월 15일
편집: madhan ravi 2020년 6월 15일
clear theta
theta = 0:360;
Ac = 5;
k = 2000;
m = 0.001;
RPM = 1500;
x = theta * 0;
ix = (theta>110) & (theta<170);
x(ix)= (Ac/k)*(1+sind(sqrt(k/m).*(theta(ix)/6*RPM)-(pi/2)));
plot(theta,x);

댓글 수: 4

Amazing, I got the desired result. Thank you very much
John D'Errico
John D'Errico 2020년 6월 15일
편집: John D'Errico 2020년 6월 15일
Let me just expand on what @madhan ravi wants to do here.
if does not work on each element of a vector, one element at a time. This is a common mistake I see made. An if statement is not an implicit loop.
(It looks as if he fixed what he wrote between the time I started this comment and hen I submitted it.)
Thank you John :)
@madhan ravi @John D'Errico
I was implementing the solution given by you, but i encountered the following problem in which array A size is fixed which is (73,1). Hence, when i go to plot, matlab gives an error saying the left and right sides are not same. The code is,
theta = 0:360;
x = theta * 0;
ix = (theta>110) & (theta<=173);
x(ix)= A;
plot(theta,x,'b');
This code is giving me blank plot. However, when i try to plot with theta>100 & theta>=173,(i.e. with same size as A), i get the plot.
I was thinking about using a linspace command to split theta from 110 to 173 in 73 equal portions and then plotting, unfortunately after multiple tries and getting blank plots, i think that too is not possible.
Can you suggest me something, where i can plot even with different arrays on both sides.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

질문:

2020년 6월 15일

댓글:

2020년 6월 16일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by