My graph isn't picking up my time increments. How can I fix it? My loop generates my x values, but I'm trying to graph them over time.
Show older comments
% Ch=(Chd-Chs)e^(-t/ts)+Chs equation from C.3
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 any(i==0:99)
Ch(i+1)=Chd; % starts at .015 L/mmhg in chd phase
elseif i>99 & i<350
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 not picking up my y values, I'm trying to graph this over time and it's not working, it shouldn't be a straight line up and down, but its turning out that way.
4 Comments
Dyuman Joshi
on 25 Sep 2023
It is plotting according to the code you have written.
"I'm trying to graph this over time and it's not working"
You will have to be more specific with "it's not working". What does "it's not working" mean in this context?
"it shouldn't be a straight line up and down, but its turning out that way."
Do you have a reference solution you are using to compare the output against?
BAILEY MCMASTER
on 25 Sep 2023
Dyuman Joshi
on 25 Sep 2023
Can you attach the reference equations you are trying to plot?
BAILEY MCMASTER
on 25 Sep 2023
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!
