How do I use fill to create continuous error bars?
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Justin Osborn
am 13 Okt. 2020
Kommentiert: Adam Danz
am 13 Okt. 2020
I was using the code to create continous error bars as referenced here, but could not get it to work for my dataset. Whenever I try and graph the data as a shaded area, I instead only get lines at each data point. I was able to get it to work for the values referenced in the example code, but cannot get it to work for my data set. How do I fix this?

n = 0;
for f = 500:25:1000
n = n+1;
freq(n) = f;
[Z_e_tot(n), Z_e_tot_err(n), R_e_tot(n), R_e_tot_err(n), X_e_tot(n), X_e_tot_err(n)] = imped_calc(f);
disp(f);
end;
figure()
hold on;
new_err = 1.*Z_e_tot_err;
fill([freq; flipud(freq)],[Z_e_tot-new_err;flipud(Z_e_tot+new_err)],[.9 .9 .9], 'linestyle', 'none');
line(freq, Z_e_tot);
2 Kommentare
Cris LaPierre
am 13 Okt. 2020
It looks like we need your imped_calc function to be able to see what is happening. Can you attach it? Use the paperclip icon.
Akzeptierte Antwort
Adam Danz
am 13 Okt. 2020
Bearbeitet: Adam Danz
am 13 Okt. 2020
Having the imped_calc function matters because now we can see the size and shape of the outputs.
- freq is a 1x21 vector.
- Z_e_tot and new_err are a 1x21 vectors
so the first input to fill() is [freq, flipud(freq)] which results in a 1x42 vector.
The second input is [Z_e_tot-new_err; flipud(Z_e_tot+new_err)] which results in a 2x21 vector.
This causes an unreported error,
Error using fill
Vectors must be the same length.
What you probably wanted to do is,
fill([freq, fliplr(freq)],[Z_e_tot-new_err,fliplr(Z_e_tot+new_err)],[.9 .9 .9], 'linestyle', 'none');
- The first two inputs are row vectors so you should horizontally concatenat them with ",". The 2nd input in your attempt used vertical concatenation with ";".
- Because they are row vectors you want to use fliplr, not flipud.
4 Kommentare
Adam Danz
am 13 Okt. 2020
Glad I could help. As Cris LaPierre has shown, the inputs can also be column vectors of the same length. What matters is that the sizes of the first two inputs agree in such a way that Matlab can interpret the vertices of the patch object.
Weitere Antworten (1)
Cris LaPierre
am 13 Okt. 2020
Having your functino may not technically be necessary, but it sure makes it easier to ensure we are seeing what you see. In this case, your code is creating row vectors, but the solution you are using expects column vectors. Having your code create column vectors is all that is necessary to get your code to run. Instead of (n), use (n,1).
n = 0;
for f = 500:25:1000
n = n+1;
freq(n,1) = f;
[Z_e_tot(n,1), Z_e_tot_err(n,1), R_e_tot(n,1), R_e_tot_err(n,1), X_e_tot(n,1), X_e_tot_err(n,1)] = imped_calc(f);
end
new_err = 1.*Z_e_tot_err;
fill([freq; flipud(freq)],[Z_e_tot-new_err;flipud(Z_e_tot+new_err)],[.9 .9 .9], 'linestyle', 'none');
line(freq, Z_e_tot);
0 Kommentare
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

