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 个评论
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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Octave 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!