You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How do I convert a linear scale array to a logarithmic without getting negative values?
1 view (last 30 days)
Show older comments
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 Comment
Answers (1)
madhan ravi
on 6 Jul 2020
Replace < 1 with nan.
14 Comments
farzad
on 6 Jul 2020
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));
farzad
on 7 Jul 2020
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.
farzad
on 7 Jul 2020
please see the attached. the distances of the lines is in logarithmic scale. this is how you can do in Excel :
farzad
on 7 Jul 2020
Thank you ! it worked on scaling , but all the bars disappeared ! I wanted to use the log scale to see the small bars better !
farzad
on 8 Jul 2020
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
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)