How matlab converts data from linear scale to log scale?

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 Comment

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.

Sign in to comment.

 Accepted Answer

>> 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

I want to calculate slope of graph in log scale from 100 and need to know what is the equal of 100 in linear scale.so how can i get it?
First, an improved version of your plot:
may = xlsread('may.xlsx','msd','A1:F1000');
t = may(:,2);
y = may(:,6);
fig = figure(1);
clf(fig);
ax1 = axes(fig);
plot(ax1, t,y,'r');
ax1.XColor = 'r';
ax1.YColor = 'r';
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position', ax1_pos, ...
'Color', 'none');
plot(ax2, t, y, 'Color','k')
set(ax2, 'yscale', 'log', 'xscale', 'log', ...
'XLim', ax1.XLim, ...
'XAxisLocation', 'top', ...
'YAxisLocation',' right' );
I want to calculate slope of graph in log scale from 100 and need to know what is the equal of 100 in linear scale
You want the x location for which the log10 is 100 ?? That would correspond to x = 10^100 in linear scale, but your data only goes to x = 3000.
How matlab converts data from linear scale to log scale?
MATLAB uses OpenGL for most plotting. It does not draw graphs itself, and does not calculate every point itself. Instead it creates "vertex lists" and linear transform objects to send to OpenGL, puts together complicated objects mostly using line and fill and text primitives, and then asks OpenGL to render the scene.
In order to handle log plots, MATLAB sends log10 of the data coordinates to OpenGL. In-between the provided coordinates, OpenGL draws straight lines. There is no level that automatically adds additional line segments so as to get a more accurate representation in log scale !!!
The fact that log10 of a given range is typically smaller than the range (e.g., 10 to 100 is a change of only one unit) is not explicitly taken into account. Instead, you simply have the situation that there are fewer log10 units to be spread across the defined number of pixels, so the log10 units are given more space each: physical linear scale on display according to drawing scale = pixel_distance / ceil(log10(max(x)-min(x)))
That's exactly my question and i don't know how to find the equivalent data.
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.
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance 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!