Anottations are overlapping in each loop interaction
조회 수: 8 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!