
Label each line from plot automatically
30 ビュー (過去 30 日間)
古いコメントを表示
I have the following plot generated by the curve fitting tool application

I would like to instead of having the legend, to plot the labels on top of each line in a given x value (for example x = 7). I have seen people use the text() command, but I would like to know if there's any "automatic" way of doing it and avoid having to write all the exact points.
The code I use to plot one line is the following:
x = 1.5; %linewidth
set(p,'linewidth',x);
p = plot(fitresult{5},'b');
Thanks
0 件のコメント
回答 (1 件)
Ameer Hamza
2020 年 4 月 1 日
Somethis like this
t = linspace(0,10, 100)';
y = sqrt(t).*linspace(1,1.5,5);
idx = find(t > 7, 1);
text_x = repmat(t(idx), 1, size(y,2));
text_y = y(idx, :);
labels = {'label1', 'label2', 'label3', 'label4', 'label5'};
plot(t,y)
hold on
t = text(text_x, text_y, labels, 'Color', 'k');

2 件のコメント
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!