How matlab converts data from linear scale to log scale?
36 views (last 30 days)
Show older comments
Najmeh Eskandari
on 3 Sep 2020
Commented: Walter Roberson
on 4 Sep 2020
Hi.
I plot the figure from column 2 (as x) and column 6 (as y) in excel file in linear and log scale. Why 1500 in linear scale is100 in logarithmic scale? How matlab changes data (t1 and y1) into logarithmic form and how plot that?
The code:
may=xlsread('may.xlsx','msd','A1:F1000');
t=may(:,2);
y=may(:,6);
figure(1)
plot(t,y,'r');
ax1 = gca; % current axes
ax1.XColor = 'r';
ax1.YColor = 'r';
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
%xlim([100 10000])
t1=may(:,2);
y1=may(:,6);
hold on
plot(t1,y1,'Parent',ax2,'Color','k')
ha=gca;
set(ha,'yscale','log');
set(ha,'xscale','log');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/355864/image.png)
Thanks
1 Comment
David Hill
on 3 Sep 2020
You can see the end points are the same. The black has the black axes and the red has the red axes, but the axes do not correlate to each other.
Accepted Answer
Walter Roberson
on 3 Sep 2020
>> ax1.XLim
ans =
0 3000
>> ax2.XLim
ans =
1 10000
You did not linkaxes(), so the XLim are set independently of each other. The automatic scale setting prioritizes "nice" numbers. 10^ceil(log10(3000)) --> 10000
7 Comments
Walter Roberson
on 4 Sep 2020
Which is exactly your question?
You would have to interpolate a lot to find the location whose log10 is 100.
p = polyfit(log10(y), log10(t), 1);
t100 = 10.^polyval(p, 100)
It is strongly doubtful that you can mathematically justify using a plain log-log interpolation so far out.
Walter Roberson
on 4 Sep 2020
In the forward direction,
fp = polyfit(log10(t), log10(y), 4);
gives a quite good fit for the data that exists. And you can also reasonably use degree 4 on t vs y like I did above. But the interpolation for that at log10(y) = 100 gives a t way out of range.
In order to interpolate out anywhere close to as far as you want to (to the point where y has reached 10^100) then you need a really good model of what your data is.
More Answers (0)
See Also
Categories
Find more on Discrete Data 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!