# Why are my error bars multicoloured with no line?

4 visualizzazioni (ultimi 30 giorni)
Kristiaan Winkel il 21 Apr 2024
Commentato: Adam Danz il 22 Apr 2024
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (2)

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 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
Kristiaan Winkel il 21 Apr 2024
Thanks
Adam Danz il 22 Apr 2024

Accedi per commentare.

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]);
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]);
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)
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)))
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

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

R2023a

### Community Treasure Hunt

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

Start Hunting!

Translated by