Why are my error bars multicoloured with no line?
조회 수: 6 (최근 30일)
이전 댓글 표시
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)
댓글 수: 0
답변 (2개)
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
Adam Danz
2024년 4월 22일
@Kristiaan Winkel reminder to accept VBBV's answer if this addressed your question.
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Errorbars에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!