Hello
I have data from excel and I imported and everything going fine except error bar doesn't work
I have an error bar in column 3, this is the first time I use it.
Thank you in advance.
A=importdata('value.xlsx')
x=A.data(:,2)
b=A.data(:,1)
err=A.date(:,3)
S1=plot(x,b,err,'sk','MarkerFaceColor','k')
error(x,b,err)

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 7 Okt. 2019

0 Stimmen

The function to plot error bars is errorbar() not error()

13 Kommentare

A=importdata('value.xlsx')
x=A.data(:,2)
b=A.data(:,1)
err=A.date(:,3)
S1=plot(x,b,err,'sk','MarkerFaceColor','k')
errorbar(x,b,err)
still doesnt work.
Walter Roberson
Walter Roberson am 7 Okt. 2019
Can you attach your data so we can test?
Walter Roberson
Walter Roberson am 7 Okt. 2019
Is it correct that you want to load err from a different variable ? x and b are loaded from A.data but err is loaded from A.date -- data compared to date
Abdullah Al Alhareth
Abdullah Al Alhareth am 7 Okt. 2019
attached,
also error bar loaded from A data. as well which is the 3rd column.
Walter Roberson
Walter Roberson am 7 Okt. 2019
What are you expecting when you use plot() to plot three variables? Are you expecting a 3D scatter plot? If so then use plot3() or scatter3()
Abdullah Al Alhareth
Abdullah Al Alhareth am 7 Okt. 2019
scatter
I want to know the right code for get the values of error bar from excel and plot it.
Walter Roberson
Walter Roberson am 7 Okt. 2019
data = readtable('value.xlsx', 'ReadVariableNames',false);
x = data{:,1};
b = data{:,2};
err = data{:,3};
[sx, idx] = sort(x);
sb = b(idx);
serr = err(idx);
plot(sx, sb, 'sk', 'MarkerFaceColor','k');
errobar(sx, sb, serr);
Abdullah Al Alhareth
Abdullah Al Alhareth am 7 Okt. 2019
basically I plot x and y from data A which is columns 1 and 2.
Now my error bar in column 3 and I want to use it as an error bar.
Walter Roberson
Walter Roberson am 7 Okt. 2019
That is what the code I posted does. It takes time to sort the data because your x was not in order, which was leading to lines doubling back on themselves.
Abdullah Al Alhareth
Abdullah Al Alhareth am 7 Okt. 2019
Bearbeitet: Walter Roberson am 7 Okt. 2019
Ok , forget about the excel file I uploaded , let’s just do it in the original code which it import data from excel, my error bar is column 3. Which code will be working with it ?
A=importdata('value.xlsx') x=A.data(:,2) b=A.data(:,1) errorbar=A.date(:,3) S1=plot(x,b,errorbar,'sk','MarkerFaceColor','k').
I Tried this one and doesn’t work. keep it as importdata. I want to learn the right code so I can use it for another xlsx files.
Thank you in Advance.
Walter Roberson
Walter Roberson am 7 Okt. 2019
readtable() is the right code. importdata() is older and fragile, returning different data types depending on whether it finds headers in the file or not.
But if you insist:
filename = 'value.xlsx';
A = importdata('value.xlsx');
x = A.data(:,2);
b = A.data(:,1);
err = A.data(:,3);
[sx, idx] = sort(x);
sb = b(idx);
serr = err(idx);
plot(sx, sb, 'sk', 'MarkerFaceColor', 'k')
errorbar(sx, sb, serr)
The sort() step will not hurt if the data is already sorted, and will help if the data is in the wrong order.
Abdullah Al Alhareth
Abdullah Al Alhareth am 7 Okt. 2019
Actually the excel I uploaded it's not the right one, but the data I have all three column It should be in same order, for example if I sorted x then the data will be missed up. That's why.
Walter Roberson
Walter Roberson am 7 Okt. 2019
filename = 'value.xlsx';
A = importdata('value.xlsx');
x = A.data(:,2);
b = A.data(:,1);
err = A.data(:,3);
plot(x, b, 'sk', 'MarkerFaceColor', 'k')
errorbar(x, b, err)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by