How do I convert a linear scale array to a logarithmic without getting negative values?

Hi All
I need to plot ( bar plot) values, and on the X axis , I want to convert them to logarithmic, but the values <1 become negative. how to avoid and fix it ?

Answers (1)

Replace < 1 with nan.

14 Comments

this is what I do , I take the log immediately when I am plotting I doubt I can do what you say, how do I do that ?
f=barh(y, log(x), 'basevalue', min(x));
f=barh(y, max(0,log(x)), 'basevalue', 0);
If you want to replace values, you will have to store the intermediate result, or write a function that does that.
thank you very much for your answer. yes this is right but : I think something is wrong.
Because : here we are actually taking the logarithm of the X axis values. so if the maximum is 10^ 4 , the max on the logarithmic will be 4.
but I meant only changing the scale of showing the values , therefore , not touching the actual X values, but changing the X values. the same way it is done in Excel.
You can change the axis if you like. What exactly do you want to happen?
please see the attached. the distances of the lines is in logarithmic scale. this is how you can do in Excel :
Thank you ! it worked on scaling , but all the bars disappeared ! I wanted to use the log scale to see the small bars better !
the scaling should be only along X, cause the bars are along X axis
Any opinions on why the bars disappear ? the divisions start from 10^-1 to 10^4 and I should have a graph in this range

Sign in to comment.

Asked:

on 6 Jul 2020

Commented:

on 9 Jul 2020

Community Treasure Hunt

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

Start Hunting!