I am trying to add error bars to a loglog plot and matlab and nothing I try is working. I've gone about it in many different ways including plotting using plot(x,y) then changing the scale to log, using loglog(x,y), and trying errorbarlogx. I dont know why the error is only above the data point for the later points (it shouldnt be). This is my code that made the above graph.
loglog(distance,radiation)
log_distance=log(distance);
log_radiation=log(radiation);
fit=polyfit(log_distance,log_radiation,1)
m=fit(1)
b=fit(2)
z=polyval(fit,log(distance))
hold on;
errorbar(distance,exp(z),combined_error)
What am I doing wong?

4 Kommentare

Adam Danz
Adam Danz am 23 Mär. 2022
Bearbeitet: Adam Danz am 23 Mär. 2022
Could you provide the values for inputs to errorbar?
Perhaps the easiest way to share them is to save them to a mat file and attach the file in a comment or within the question.
Also let us know if there are any error message or warnings and, if so, provide the entire error/warning text.
Tim Keegan
Tim Keegan am 23 Mär. 2022
I attatched it to this
Tim Keegan
Tim Keegan am 23 Mär. 2022
I get warning:negative data ignored every time I run it
Adam Danz
Adam Danz am 23 Mär. 2022
See Star Strider's answer.
You may also want to review some log properties

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Star Strider
Star Strider am 23 Mär. 2022

0 Stimmen

You are likely not doing anything wrong. The lower error bars are most likely negative, and values less than or equal to zero do not plot on a logarithmic axis scale. (Those logarithms are defined, however they are complex, and purely imaginary values do not plot in MATLAB.)

5 Kommentare

Tim Keegan
Tim Keegan am 23 Mär. 2022
but the experimental curve is not within (or even close) to the error bars when they are only above the line of best fit. The experimental curve never gets negative on the loglog plot, so why do the error bars not go down to the experimental curve?
Star Strider
Star Strider am 23 Mär. 2022
The lower values of some of the error bars are negative. That’s the reason they’re not plotted.
The error bars are likely defined in a way that produces negative values. If you plot them on a linear y-axis scale, they should all be visible, and the ones that are not plotted on the logarithmic y-axis scale will be negative when plotted on the linear scale.
Tim Keegan
Tim Keegan am 23 Mär. 2022
Thank you. Is there any way for me to get the error bars to look normal on the loglog axis? I'm required to do it on a loglog axis for my class.
Adam Danz
Adam Danz am 23 Mär. 2022
> Is there any way for me to get the error bars to look normal on the loglog axis?
see this related answer
Tim Keegan
Tim Keegan am 23 Mär. 2022
thank you @Adam Danz that worked.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by