- 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!