My graph is not picking up my time increments, its suppose to have a nice curve, but its coming out as a straight line.
Show older comments
clear
Ts=30; % ms
Td=60; % ms
Chs=.001; % L/mmhg
Chd=.015; % L/mmhg
N=800; % number of elements
t=0:1:800; % all time values together
for i=0:N
if i<=99
Ch(i+1)=Chd; % starts at .015 L/mmhg in chd phase
elseif i>99 & i<=349
Ch(i+1)=(Chd-Chs)*exp((-t(i))/Ts)+Chs; % switches to chs
elseif i>349
Ch(i+1)=(Chs-Chd)*exp((-t(i))/Ts)+Chd; % switches back to chd
end
end
timebase=0:.01:8; % putting back in s
plot(timebase,Ch)
grid on
ylim([0 .02])
xlabel('time(s)')
ylabel('Ch (L/mmHg')
It's suppose to look like this.

Accepted Answer
More Answers (1)
Vectorised version —
clear
Ts=30; % ms
Td=60; % ms
Chs=.001; % L/mmhg
Chd=.015; % L/mmhg
N=800; % number of elements
t=0:1:800; % all time values together
Lv1 = t<=99;
Ch(Lv1) = Chd;
Lv2 = t>99 & t<=349;
Ch(Lv2) = (Chd-Chs)*exp(-t(1:nnz(Lv2))/Ts)+Chs; % switches to chs
Lv3 = t > 349;
Ch(Lv3) = (Chs-Chd)*exp(-t(1:nnz(Lv3))/Ts)+Chd; % switches back to chd
timebase=0:.01:8; % putting back in s
plot(timebase,Ch)
grid on
ylim([0 .02])
xlabel('time(s)')
ylabel('Ch (L/mmHg')
.
Categories
Find more on MATLAB 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!


