How to plot using the mod function?

8 ビュー (過去 30 日間)
Akhil Vasvani
Akhil Vasvani 2017 年 4 月 26 日
コメント済み: Akhil Vasvani 2017 年 4 月 27 日
I'm trying to plot an energy graph, and I'm having trouble plotting both the mod function. I don't understand why I cannot plot each point when mod(t,etime) == 0 and mod(t,ptime) == 0. The mod(t,etime) == 0 function only plots at the end, and I would like it to plot continuously. Could someone please help me figure this out?
function MDSim(T,sigma,m,dt,rc,L,k,ptime,etime)
tempcontrol=input('Would you like Temperature Control? [Y/N] \n','s');
while (tempcontrol ~= 'n' && tempcontrol ~= 'y')
tempcontrol=input('Would you like Temperature Control? [Y/N] \n', 's');
end
[xpos,ypos,vx,vy]=Initialize(sigma,L,k);
h=cell(8);
for i=1:64
h{i}=rectangle('Position',[xpos(i)-0.5*sigma ypos(i)-0.5*sigma sigma sigma],'Curvature',[1 1], 'FaceColor','b');
axis equal
end
t=0;
while T > t
t=t+1;
[xpos,ypos,vx,vy,U_tot,K_avg_tot,E_tot]=Step(xpos,ypos,vx,vy,dt,m,L,sigma,rc,k,tempcontrol);
if mod(t,ptime) == 0
for j=1:64
figure(1);
set(h{j},'Position',[xpos(j)-0.5*sigma ypos(j)-0.5*sigma sigma sigma])
axis equal
end
hold on
drawnow
hold off
end
if mod(t,etime) == 0
%disp(['Total Energy is: ', num2str(E_tot)])
figure(2);
plot(t,(U_tot),'rd', t,(K_avg_tot),'b+',t,(E_tot),'m*')
title('Total Energy (E), Potential Energy (U),Kinetic Energy (K) vs. Time (s)');
xlabel('Time (ds)');
ylabel('Energy (J)');
legend('E','U', 'K', 'Location', 'EastOutside');
hold on
drawnow()
hold off
end
end
end
%

採用された回答

Walter Roberson
Walter Roberson 2017 年 4 月 26 日
You appear to be successfully plotting at the times you would like to. You just are not asking for the plot that you think you are.
if mod(t,etime) == 0
disp(['Total Energy is: ', num2str(E_tot)])
disp(count);
plot(t, (U_tot), '*') %notice change
axis equal
%scatter(t,E_tot);
%set(ph, 'XData', t);
%set(ph,'YData', U_tot);
%,t,K_avg_tot,'-',t,E_tot,'-')
hold on %notice change
drawnow() %notice change
end
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 4 月 27 日
After
h{i}=rectangle('Position',[xpos(i)-0.5*sigma ypos(i)-0.5*sigma sigma sigma],'Curvature',[1 1], 'FaceColor','b');
and
hold on
Akhil Vasvani
Akhil Vasvani 2017 年 4 月 27 日
Thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by