How to find data values that falls on line connecting loglog plot in matlab
81 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Star Strider
2020-1-23
To get a smooth interpolation, it is necessary to do two transformations on it. First, interpolate log(y), and then take the exponential of the interpolated result:
yq = exp(interp1(x,log(y),xq,'linear'));
更多回答(1 个)
Sindar
2020-1-23
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 个评论
Sindar
2020-1-24
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.^
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!