How can I create multiple lines with error bars and a legend?

1 次查看(过去 30 天)
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.

回答(1 个)

ag
ag 2025-5-2
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!

类别

Help CenterFile Exchange 中查找有关 Errorbars 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by