- 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 次查看(过去 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.
0 个评论
回答(1 个)
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Errorbars 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!