My graph is not picking up my time increments, its suppose to have a nice curve, but its coming out as a straight line.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
BAILEY MCMASTER
am 25 Sep. 2023
Kommentiert: William Rose
am 25 Sep. 2023
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.
0 Kommentare
Akzeptierte Antwort
William Rose
am 25 Sep. 2023
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)-99)/Ts)+Chs; % switches to chs
elseif i>349
Ch(i+1)=(Chs-Chd)*exp(-(t(i)-349)/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')
Good luck.
5 Kommentare
William Rose
am 25 Sep. 2023
@BAILEY MCMASTER, you are welcome. The answer from @Star Strider is more elegant than my answer. @Star Strider's answer modifies your code in more significant ways. You and I can both learn from it.
William Rose
am 25 Sep. 2023
Your equation for the second phase (rising phase) does something which I suspect is not what you want: It starts the rising phase at Ch()=Chs. This is not a problem with the time constants and start times in this particular case, since the signal Ch() is very close to Chs before the rising phase begins. But what if the timing was such that Ch() had not yet decayed to Chs? With your current method, Ch() would instantly jump down to Chs, to begin its rising phase. That would be weird. See below, where I have changed Ts from 30 to 150 ms to illustrate my point.
clear
Ts=150; % 150 ms, not 30
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)-99)/Ts)+Chs; % switches to chs
elseif i>349
Ch(i+1)=(Chs-Chd)*exp(-(t(i)-349)/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')
A better approach is to have Ch() begin its rising phase from whatever value it currently has.
Weitere Antworten (1)
Star Strider
am 25 Sep. 2023
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')
.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Sparse Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!