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. similarly pressure and velocity is also plotted.
1 次查看(过去 30 天)
显示 更早的评论
I want the graph to be colored in such a way that stage one is in blue and stage 2 is in red in displ vs time graph, similarly for velocity vs time and pressure vs time graph. I have posted image as example. I want the graph to be like that in image. How do i write the code?
![example.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202752/example.png)
displ=zeros(100,2);
tim=zeros(100,1);
pressure=ones(100,1);
velocity=ones(100,1);
for i=2:100
v=5;
dt=1*10^-4;
function [displ_f,pressure]=stage1(displ_i)
dt=1*10^-4;
v=5;
area=5;
displ_f=displ_i+v*dt;
pressure=area*displ_f;
velocity=10*area*displ_f;
end
function [displ_f]=stage2(displ_i)
dt=1*10^-4;
v=5;
area=5;
displ_f=displ_i+v*dt;
pressure=area*displ_f;
velocity=10*area*displ_f;
end
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
plot(tim(:,1),displ(:,1));
plot(tim(:,1),pressure);
plot(tim(:,1),velocity);
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!