Azzera filtri
Azzera filtri

Why are my error bars multicoloured with no line?

5 visualizzazioni (ultimi 30 giorni)
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)

Risposte (2)

VBBV
VBBV il 21 Apr 2024
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 Commenti
Adam Danz
Adam Danz il 22 Apr 2024
@Kristiaan Winkel reminder to accept VBBV's answer if this addressed your question.

Accedi per commentare.


Adam Danz
Adam Danz il 22 Apr 2024
Modificato: Adam Danz il 22 Apr 2024
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.

Categorie

Scopri di più su Errorbars in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by