Why are my error bars multicoloured with no line?

조회 수: 6 (최근 30일)
Kristiaan Winkel
Kristiaan Winkel 2024년 4월 21일
댓글: Adam Danz 2024년 4월 22일
When I run this very simple code the graph plotted has multicoloured error bars and no joining line? Why.
figure(24)
x = 20:1:25;
y = [1.75 1.78 1.81 1.85 1.9 1.95];
err = 0.1;
errorbar(x,y,err)

답변 (2개)

VBBV
VBBV 2024년 4월 21일
x = 20:1:25;
y = [1.75 1.78 1.81 1.85 1.9 1.95];
err = repmat(0.1,length(x),1);
errorbar(x,y,err)
  댓글 수: 3
Kristiaan Winkel
Kristiaan Winkel 2024년 4월 21일
Thanks
Adam Danz
Adam Danz 2024년 4월 22일
@Kristiaan Winkel reminder to accept VBBV's answer if this addressed your question.

댓글을 달려면 로그인하십시오.


Adam Danz
Adam Danz 2024년 4월 22일
편집: Adam Danz 2024년 4월 22일
Understanding array size compatibility
errorbar, like plot, supports mixed array sizes in input arguments as long as the sizes are compatible. This feature was added to errorbar in R2022b. Array size compatibility means that elements of one argument have a correspondence to elements of another argument. For example, one argument can be a 2x3 array and another argument can be a 1x2 or 1x3 vector.
For example, the first argument below is 3x2 and the second argument is 1x2. This tells MATLAB to map the vector values to the columns of the matrix. It produces 3 objects because the rows are the unmatched dimension and there are 3 rows.
errorbar([1 2; 3 4; 5 6], [.4 .9]);
axis padded; grid on
Now, make a small changed. Set the second argument to a 3x1 vector. Now the MATLAB will map the vector values to the rows of the matrix. It produces 2 objects because now the columns are the unmatched dimension and there are 2 columns.
figure()
errorbar([1 2; 3 4; 5 6], [.4 .9 .3]);
axis padded; grid on
In the exampled posted by the OP, the third argument is a scalar but the first and second arguments are 1x6 vectors. The 1x1 scalar maps to the number of rows in the other arguments. Six objects are produced because there are 6 columns of data in the unmatched dimension. Since each object only has 1 point, there are no connector lines.
figure()
x = 20:1:25;
y = [1.75 1.78 1.81 1.85 1.9 1.95];
err = 0.1;
errorbar(x,y,err)
axis padded; grid on
As @VBBV explained, to produce a single object instead of six objects, specify the error for each value of x and y.
figure()
x = 20:1:25;
y = [1.75 1.78 1.81 1.85 1.9 1.95];
err = 0.1;
errorbar(x,y,err.*ones(size(x)))
axis padded; grid on
Is this something readers would like to learn more about? I wonder if a blog article on this topic would be useful. Please let me know if anyone has questions.

카테고리

Help CenterFile Exchange에서 Errorbars에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by