Anottations are overlapping in each loop interaction

8 ビュー (過去 30 日間)
Robson Passos
Robson Passos 2018 年 4 月 30 日
編集済み: Robson Passos 2018 年 5 月 1 日
In the following code I am plotting a graph for each loop interaction. I want to put a text box in the graphics window showing a value that varies for each interaction. However, the values in the text box are overlapping. The code is running normally, just run it to see the problem. Does anyone know how to fix this? If someone helps me I'll be very grateful.
close all; clear all; clc;
m = 1; %[Kg] Mass of the oscillating element
Fo = 1; %[N] Intensity of external force
Ao = 1; %[m] Initial amplitude
phi = 0; %phase
Wo = 1; %[1/s]
b = 1;
bc = 2*m*Wo;
tau = m/b;
W = 0:0.1:Wo;
t = 0:0.1:60;
figure;
set(gcf,'color','white')
for i=1:length(W)
u(:,i) = (Fo/(m*abs(Wo^2 - W(i))))*cos(Wo* t + phi) + (Ao*exp(-t/tau).*cos((Wo*sqrt(1 - (b/bc)^2))*t + phi));
pause (1)
plot(t,u(:,i));
grid on
axis([1,65,-40,40])
str = num2str(W(i));
dim = [.75 .5 .3 .3];
annotation('textbox',dim,'String',str,'FitBoxToText','on');
end

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 1 日
Write you for loop like this
a = [];
for i=1:length(W)
u(:,i) = (Fo/(m*abs(Wo^2 - W(i))))*cos(Wo* t + phi) + (Ao*exp(-t/tau).*cos((Wo*sqrt(1 - (b/bc)^2))*t + phi));
pause (1)
plot(t,u(:,i));
grid on
axis([1,65,-40,40])
str = num2str(W(i));
dim = [.75 .5 .3 .3];
delete(a);
a = annotation('textbox',dim,'String',str,'FitBoxToText','on');
end
  2 件のコメント
Robson Passos
Robson Passos 2018 年 5 月 1 日
Thank you very much.
Ameer Hamza
Ameer Hamza 2018 年 5 月 1 日
You are welcome.

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

その他の回答 (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