Anottations are overlapping in each loop interaction
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Robson Passos
am 30 Apr. 2018
Bearbeitet: Robson Passos
am 1 Mai 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
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!