Plotting results one at a time like simulation
7 次查看(过去 30 天)
显示 更早的评论
close all
clear all
Colour=hsv ;
R =.95000 ; % sistemski periferni otpor (mmHg/cmˆ3/sec )
C = 1.0666 ; % sistemska arterijska uskladjenost (cmˆ3/mmHg)
%%Predpostavka
Tc=60/72;% 72 otkucaja u minuti
Ts=(2/5)*Tc ; % sistolni period
cycle=5; % Broj cikrkulacija za analizu
% Modelovanje krvnog protoka u aorti
syms ti q
I0= solve(90-int(q * (sin (pi*ti/Ts)), ti,0, Ts),q);
I0=subs(I0,'3.14',pi);
sine = @(t) sin(pi*t/Ts);
I =@(t) I0*sine(t).*(t <= Ts); %za jednu cirkulaciju
% Analiza cirkulacija
for n=1:cycle
t=(n-1)*Tc:.01:n*Tc;
% Krvni protok cirkulacije
I = @(t) I0*sine(t-(n-1)*Tc).*(t <= ((n-1)*Tc+Ts));
plot(t,I(t),'LineWidth',2)
hold on
xlim([0 n*Tc])
ylim([ 0 600])
title ( ' Aortni krvni pritisak ' )
ylabel ( ' Krvni protok (ml/ s ) ' )
xlabel ( ' vreme ( s ) ' )
end
Hey guys,can someone help me with this. Its working properly but what i need to do next is to plot the results one at a time so i can see basicly line drawing it selt,something like a simulation... Appreciate the help!!!
0 个评论
回答(1 个)
Geoff Hayes
2014-12-11
Nikola - there are probably several ways to do this, so here is one that you should be able to adapt for your purposes. Suppose that we wish to draw 100 points of the sine wave, from -2pi to +2pi, and see the curve "grow" over time. We could do this as follows
% generate the sine data
x = linspace(-2*pi,2*pi,100);
y = sin(x);
% create the figure and an empty plot graphics handles
figure;
hPlot = plot(NaN,NaN);
% set the limits
xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
% draw the curve
for k=1:length(x)
% update the data
set(hPlot,'XData',x(1:k),'YData',y(1:k));
% pause for 0.1 seconds
pause(0.1);
end
Rather than calling plot a multiple of times, which will create multiple graphics handles, we just call it the once and then update its x and y data on each iteration of the loop, adding one more point at at time. Try incorporating the above into your code and see what happens!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!