How matlab converts data from linear scale to log scale?

조회 수: 34 (최근 30일)
Najmeh Eskandari
Najmeh Eskandari 2020년 9월 3일
댓글: Walter Roberson 2020년 9월 4일
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