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 日間)
古いコメントを表示
Lakshmikruthiga Ponnusamy
2019 年 1 月 7 日
コメント済み: Walter Roberson
2019 年 1 月 8 日
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!