how to add "drawnow" function in it?

43 views (last 30 days)
SAHIL SAHOO
SAHIL SAHOO on 3 Oct 2022
Answered: Jan on 4 Oct 2022
ti = 0;
tf = 1E-2;
tspan=[ti tf];
y0 = [(10E-6).*rand(6,1);((-3.14).*rand(2,1) + (3.14).*rand(2,1))]; % intial conditions
o = sort(10e3*rand(1,2),'ascend'); %detuning frequency
tc = 10E-6;
[T,Y]= ode45(@(t,y) rate_eq(t,y,o),tspan,y0);
% I want to plot this by using "drawnow" for this, how can I add here?
plot3(Y(:,4),Y(:,5),Y(:,6));
xlabel("A1");
ylabel("A2");
zlabel("A3")
grid on
function dy = rate_eq(t,y,o)
dy = zeros(8,1);
P = 0.2;
a = 0.1;
tf = 230E-6;
tc = 30E-9;
k = 1E-3;
dy(1) = (P - y(1).*((abs(y(4)))^2 +1))./tf;
dy(2) = (P - y(2).*((abs(y(5)))^2 +1))./tf;
dy(3) = (P - y(3).*((abs(y(6)))^2 +1))./tf;
dy(4)= (y(1)-a).*((y(4))./tc) + (k./tc).*(y(5)).*cos(y(7));
dy(5)= (y(2)-a).*((y(5))./tc) + (k./tc).*(y(4)).*cos(y(7)) + (k./tc).*(y(6))*cos(y(8));
dy(6)= (y(3)-a).*((y(6))./tc) + (k./tc).*(y(5)).*cos(y(8));
dy(7) = o(1,1) - (k./tc).*((y(4)./y(5)) + (y(5)./y(4))).*sin(y(7)) + (k./tc).*(y(6)/y(5)).*sin(y(8));
dy(8) = o(1,2) - (k./tc).*((y(5)./y(6)) + (y(6)./y(5))).*sin(y(8)) + (k./tc).*(y(4)/y(5)).*sin(y(7));
end
  1 Comment
Torsten
Torsten on 3 Oct 2022
Since this is not an animated plot, you don't need "drawnow". The plot won't appear faster using this command.

Sign in to comment.

Answers (1)

Jan
Jan on 4 Oct 2022
The answer is trivial: simply add a drawnow command at the end of the code.
But the question remains, what the purpose is. You will not see any difference to the current code. So maybe you want to do something else and the assumption, that drawnow will do this, is not correct. So please explain, what you want to achieve.
Maybe you want an animated point?
axesH = axes('XLabel', 'A1', 'YLabel', 'A2', 'ZLabel', 'A3', ...
'NextPlot', 'add', 'XLim', [0, 20], 'YLim', [0, 20], 'ZLim', [0, 20]);
grid('on');
dotH = plot3(Y(1,4),Y(1,5),Y(1,6), 'g.');
for k = 2:size(Y, 1)
pause(0.05); % calls DRAWNOW implicitly
set(dotH, 'XData', Y(k,4), 'YData', Y(k,5), 'ZData', Y(k,6));
end

Categories

Find more on Graphics Performance 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!