I have the following code. The values of displ in stage1 and stage2 are plotted in displ vs time graph. Thus a single curve is obtained.

조회 수: 1 (최근 30일)
displ=zeros(100,2)
tim=zeros(100,1)
for i=2:100
v=5;
dt=1*10^-4;
function [displ_f]=stage1(displ_i)
dt=1*10^-4;
v=5;
displ_f=displ_i+v*dt;
endfunction
function [displ_f]=stage2(displ_i)
dt=1*10^-4;
v=5;
displ_f=displ_i+v*dt;
endfunction
if (displ(i-1,1)<0.020 && displ(i-1,2)>=0)
disp("IN stage 1");
[displ(i,1)]=stage1(displ(i-1,1));
displ(i,2)=v;
tim(i,1)=tim(i-1)+dt;
elseif (displ(i-1,1)>=0.020 && displ(i-1,1)<=0.0256 && displ(i-1,2)>=0)
disp("IN stage 2");
[displ(i,1)]=stage2(displ(i-1,1));
displ(i,2)=displ(i-1,2);
tim(i,1)=tim(i-1)+dt;
end
end
disp(" displ vs tim")
plot(tim(:,1),displ(:,1));
How will I get stage1 curve in orange color and stage2 curve in blue color in the same plot to know which stage has which displ values?
  댓글 수: 5
Lakshmikruthiga Ponnusamy
Lakshmikruthiga Ponnusamy 2019년 1월 8일
yeah, it is octave. Still, you can help. Matlab and octave both are similar. I didn't get any help from octave forum, so I posted it here. Kindly help.
Walter Roberson
Walter Roberson 2019년 1월 8일
Octave is a product of the Free Software Foundation . The fundamental principle of FSF is that the software should be no cost, and that you can modify it as needed , but that if you want service then you should pay for the service . Therefore if you are not satisfied with the response you got from the Octave distribution list, you should be hiring a consultant . That is the FSF way .
FSF is not a charity to provide free software because software can be hard to afford .FSF is a deliberately disruptive economic model that aims to drive proprietary software out of business, replacing it with no cost for the software and instead charging for work on the software.
FSF says that it is morally and ethically wrong to create software and not give the software away for no charge, that anyone who creates proprietary software is a Bad Person who is Doing Evil.

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

채택된 답변

nanren888
nanren888 2019년 1월 7일
편집: madhan ravi 2019년 1월 8일
Is this the sort of thing you are looking for?
displ=zeros(100,2)
tim=zeros(100,1)
stageOneMask = false([100,1]);
stageTwoMask = false([100,1]);
for i=2:100
v=5;
dt=1*10^-4;
if (displ(i-1,1)<0.020 && displ(i-1,2)>=0)
disp("IN stage 1");
[displ(i,1)]=stage1(displ(i-1,1));
displ(i,2)=v;
tim(i,1)=tim(i-1)+dt;
stageOneMask(i) = true;
elseif (displ(i-1,1)>=0.020 && displ(i-1,1)<=0.0256 && displ(i-1,2)>=0)
disp("IN stage 2");
[displ(i,1)]=stage2(displ(i-1,1));
displ(i,2)=displ(i-1,2);
tim(i,1)=tim(i-1)+dt;
stageTwoMask(i) = true;
end
disp(" displ vs tim")
plot(tim(:,1),displ(:,1),'k',tim(stageOneMask,1),displ(stageOneMask,1),'Ob',tim(stageTwoMask,1),displ(stageTwoMask,1),'Or');
end
function [displ_f]=stage1(displ_i)
dt=1*10^-4;
v=5;
displ_f=displ_i+v*dt;
end
function [displ_f]=stage2(displ_i)
dt=1*10^-4;
v=5;
displ_f=displ_i+v*dt;
end
Generally, if you know something about the structure of the problem, for example, that it has two distinct stages, maybe your code could represent that.
Sorry, I had to rearrange your code to get it sort of Matlab compliant. (Leaves it a bit of a mess, sorry)
Might want to consider rearranging it to be more in line with normal style guides?
Did I guess correctly what your "stages" were?
  댓글 수: 2
Lakshmikruthiga Ponnusamy
Lakshmikruthiga Ponnusamy 2019년 1월 8일
편집: Lakshmikruthiga Ponnusamy 2019년 1월 8일
Yeah, your guess was right. I want this type of plot you mentioned. But your answer gives me error as follows. I use octave, sorry for inconvenience.
"error: set: unknown line property Ob"

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by