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)

 採用された回答

Walter Roberson
Walter Roberson 2019 年 10 月 7 日

0 投票

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

13 件のコメント

Abdullah Al Alhareth
Abdullah Al Alhareth 2019 年 10 月 7 日
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 2019 年 10 月 7 日
Can you attach your data so we can test?
Walter Roberson
Walter Roberson 2019 年 10 月 7 日
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 2019 年 10 月 7 日
attached,
also error bar loaded from A data. as well which is the 3rd column.
Walter Roberson
Walter Roberson 2019 年 10 月 7 日
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 2019 年 10 月 7 日
scatter
I want to know the right code for get the values of error bar from excel and plot it.
Walter Roberson
Walter Roberson 2019 年 10 月 7 日
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 2019 年 10 月 7 日
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 2019 年 10 月 7 日
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 2019 年 10 月 7 日
編集済み: Walter Roberson 2019 年 10 月 7 日
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 2019 年 10 月 7 日
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 2019 年 10 月 7 日
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 2019 年 10 月 7 日
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)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by