Label each line from plot automatically

34 Ansichten (letzte 30 Tage)
Roger Gomila
Roger Gomila am 1 Apr. 2020
Kommentiert: Ameer Hamza am 2 Apr. 2020
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

Antworten (1)

Ameer Hamza
Ameer Hamza am 1 Apr. 2020
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 Kommentare
Roger Gomila
Roger Gomila am 2 Apr. 2020
I understand what you did there but i do not have a common x axis, therefore i use
[xData, yData] = prepareCurveData( x_B3_NOV_2019_2, y_B3_NOV_2019_2 );
[fitresult{1}, gof(1)] = fit( xData, yData, ft, opts );
and obtain a xData, yData for each of the 6 fitresults{} i have.
I am facing trouble fith the plotting as that fitresults{}.
Ameer Hamza
Ameer Hamza am 2 Apr. 2020
Can you show an example of your plotting code?

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by