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)

 Accepted Answer

Walter Roberson
Walter Roberson on 7 Oct 2019

0 votes

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

13 Comments

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.
Can you attach your data so we can test?
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
attached,
also error bar loaded from A data. as well which is the 3rd column.
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()
scatter
I want to know the right code for get the values of error bar from excel and plot it.
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);
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.
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.
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.
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.
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.
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)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!