- errorbar - https://www.mathworks.com/help/matlab/ref/errorbar.html
- legend - https://www.mathworks.com/help/matlab/creating_plots/add-legend-to-graph.html
How can I create multiple lines with error bars and a legend?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I got three data sets like this:
a=[8,2,3;2,5,2;5,2,4;1,7,4;4,4,5;2,3,3;3,2,6;3,4,5;3,2,4;2,1,3]
The first collum represents the base values, the second the " testing" and the third the "second testing".
I would like to present them as a line with 1x multiplied errorbar and a legend. Like this:

Unfortunately I do not manage to do with
errorbar(a,err)
Could you help me, please?
Thanks.
0 Kommentare
Antworten (1)
ag
am 2 Mai 2025
Hi Max,
To achieve your goal, you will need to provide the "errorbar" function with the dataset along with the error for each dataset.
The below code snippet demonstrates how the same:
a = [8,2,3;2,5,2;5,2,4;1,7,4;4,4,5;2,3,3;3,2,6;3,4,5;3,2,4;2,1,3];
testingData1 = a(:, 2);
testingData2 = a(:, 3);
%Modify the error data as per the need
error1 = testingData1 - a(:, 1);
error2 = testingData2 - a(:, 1);
figure;
errorbar(testingData1, error1);
hold on;
errorbar(testingData2, error2);
xlabel('X');
ylabel('Y');
legend({'Group 1', 'Group 2'}, 'Location', 'northeast');
grid on;
hold off;
For more details, please refer to the following MathWorks documentation:
Hope this helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Errorbars finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!