Anottations are overlapping in each loop interaction

8 vues (au cours des 30 derniers jours)
Robson Passos
Robson Passos le 30 Avr 2018
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

Réponse acceptée

Ameer Hamza
Ameer Hamza le 1 Mai 2018
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 commentaires
Robson Passos
Robson Passos le 1 Mai 2018
Thank you very much.
Ameer Hamza
Ameer Hamza le 1 Mai 2018
You are welcome.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by