How to find data values that falls on line connecting loglog plot in matlab
Show older comments
I tried 'interp1' with 'linear' and 'pchip' to tried to pull more data values out of the line that matlab connected my data points. Neither of them look correct when i go to plot the new data values on a loglog plot.
The problem is obvious when using the example from the Matlab Help for 'loglog'
x = logspace(-1,2);
y = exp(x);
loglog(x,y,'-s');
Then find the interpolation to get more data points in the middle, the line isn't smooth:
xq = logspace(-1,2,500);
yq = interp1(x,y,xq,'linear'); %OR% yq = interp1(x,y,xq,'pchip');
figure; loglog(xq,yq);
I must be missing something easy. Thanks.
Accepted Answer
More Answers (1)
Sindar
on 23 Jan 2020
Your interpolation is linear. Compare:
loglog(x,y,'-s',xq,yq,'r*');
and
plot(x,y,'-s',xq,yq,'r*');
Log-log interpolation can be done "by hand":
yq = 10.^interp1(log10(x),log10(y),log10(xq),'linear');
3 Comments
Sindar
on 23 Jan 2020
Since your data is smoother on a semilogy plot, use Star Strider's version. If you come upon data that is smoothest on loglog (e.g., y=x^5), you'll need to log the x-data as well. Regardless, exp() and log() are probably better than 10.^ and log10
Jeremy
on 23 Jan 2020
Sindar
on 24 Jan 2020
Yes, they are mathematically equivalent. Numerically, I think exp(log(x)) is likely to be slightly closer to x than 10.^(log10(x)) -- I think more work has been put into calculating exp() accurately (and quickly) than 10.^
Categories
Find more on Calendar 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!