How to print changing y value on plot using the "COMET" function
조회 수: 6 (최근 30일)
이전 댓글 표시
For the following code I am trying to print the y value as a function of time on the plot itself (shown here is a damped sine wave function). However, the value is not printing. Many thanks in advance for any help.
x = linspace(0,5,250);
for k = 2:length(x)
y = exp(-350.*x).*25.*cos(4.*x)+200;
ax = axes;
set(ax, 'xlim', [0 3], 'ylim', [150 300]);
hold(ax);
comet(ax,x,y)
txt = num2str(y); %%%%%%ISSUE CODE
text(2.15,275,sprintf('%d',txt)) %%%%%%ISSUE CODE
end
댓글 수: 0
채택된 답변
Walter Roberson
2018년 12월 1일
text(2.15,275,txt)
Alternately instead of assigning anything to txt use
text(2.15,275,sprintf('%d',y))
댓글 수: 2
Walter Roberson
2018년 12월 2일
if exist('lab', 'var') && ishghandle(lab); delete(lab); end
lab = text(2.15,275,sprintf('%d',y));
WIth regards to it appearing behind the plot: use a z coordinate in the text() call.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Animation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!