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.
2 views (last 30 days)
Show older comments
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?
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 Comments
Answers (0)
See Also
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!