How matlab converts data from linear scale to log scale?

48 次查看(过去 30 天)
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');
Thanks
  1 个评论
David Hill
David Hill 2020-9-3
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.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-9-3
>> 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 个评论
Walter Roberson
Walter Roberson 2020-9-4
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
Walter Roberson 2020-9-4
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by