Insert interval labels on plot

1 回表示 (過去 30 日間)
Bruno
Bruno 2014 年 1 月 29 日
コメント済み: Amit 2014 年 1 月 29 日
I have a plot with 7 intervals:
t = 0:0.001:10; x = 0.2*cos(t) + cos(1.4*t) + 0.8*cos(5.2*t) + 0.02*randn(1, 10001); N = 7; I = 1:ceil(numel(t)/N):numel(t); if (I(end) ~= numel(t)) I = [I numel(t)]; end for j = 1:N X{j,1} =[t(I(j):I(j+1))' x(I(j):I(j+1))']; end for x_fcn = @(t) 0.2*cos(t) + cos(1.4*t) + 0.8*cos(5.2*t) + 0.02*randn(1, length(t)); plot(t, x_fcn(t), '-b'); hold on plot(t(I), x_fcn(t(I)), '*r') end
How I can insert 7 labels on plot that indicates the intervals as (w1,w2,w3,w4,w5,w6,w7). Thanks

回答 (1 件)

Amit
Amit 2014 年 1 月 29 日
If you mean indicate intervals as legend then add this after the loop
legend('w1','w2','w3','w4','w5','w6','w7');
  2 件のコメント
Bruno
Bruno 2014 年 1 月 29 日
I want the labels close to the intervals on the plot and I tried (text): text('w1','w2','w3','w4','w5','w6','w7'); Is not working.
Amit
Amit 2014 年 1 月 29 日
On of the easiest way is using textbox on figure menu in 'Insert'.
However, if you want to do this via script, try this: http://www.mathworks.com/help/matlab/creating_plots/adding-text-to-graphs.html

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by