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

1 visualización (últimos 30 días)
Max Behr
Max Behr el 11 de Mayo de 2020
Respondida: ag el 2 de Mayo de 2025
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.

Respuestas (1)

ag
ag el 2 de Mayo de 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!

Categorías

Más información sobre Errorbars en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by