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 ?

回答 (1 件)

madhan ravi
madhan ravi 2020 年 7 月 6 日

0 投票

Replace < 1 with nan.

14 件のコメント

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));
Rik
Rik 2020 年 7 月 6 日
編集済み: Rik 2020 年 7 月 6 日
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.
farzad
farzad 2020 年 7 月 7 日
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.
Rik
Rik 2020 年 7 月 7 日
You can change the axis if you like. What exactly do you want to happen?
farzad
farzad 2020 年 7 月 7 日
please see the attached. the distances of the lines is in logarithmic scale. this is how you can do in Excel :
set(gca, 'XScale', 'log')
farzad
farzad 2020 年 7 月 7 日
Thank you ! it worked on scaling , but all the bars disappeared ! I wanted to use the log scale to see the small bars better !
Rik
Rik 2020 年 7 月 7 日
In X or Y?
farzad
farzad 2020 年 7 月 7 日
the scaling should be only along X, cause the bars are along X axis
farzad
farzad 2020 年 7 月 8 日
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
farzad
farzad 2020 年 7 月 9 日
any ideas ?
madhan ravi
madhan ravi 2020 年 7 月 9 日
Nope
farzad
farzad 2020 年 7 月 9 日
That's a pity, I'm stuck
farzad
farzad 2020 年 7 月 9 日
ریک, do you have any suggestions?

サインインしてコメントする。

カテゴリ

質問済み:

2020 年 7 月 6 日

コメント済み:

2020 年 7 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by