Anottations are overlapping in each loop interaction
8 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Ameer Hamza
on 1 May 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 Comments
More Answers (0)
See Also
Categories
Find more on Specifying Target for Graphics Output 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!