How to change axis of graph and interpolate data
3 次查看(过去 30 天)
显示 更早的评论
Sorry new to matlab if this seems like a basic question
Currently I have a plot that I have attached.I want to find the intersections between the plot and the line by interpolating the data. What functions/operations do i need to use on matlab
Thanks in advance
1 个评论
Star Strider
2014-6-26
It would help if you attached your plot.
The best way to do this is to save it and attach it as a ‘.fig’ file, since that contains your data as well.
采纳的回答
Star Strider
2014-6-26
This works:
% GET INFORMATON FROM FIGURE:
openfig('Figure 3#.fig');
h1c = get(gca, 'Children');
Xdc = get(h1c, 'XData');
Xd = cell2mat(Xdc);
Ydc = get(h1c, 'YData');
Yd = cell2mat(Ydc);
% CALCULATIONS:
Ydn = diff(Yd, [], 1); % Subtract line from curve to create zero-crossings
Zx = circshift(Ydn, [0 1]) .* Ydn; % Use circshift to detect them
Zxi = find(Zx < 0); % Their indices
for k1 = 1:length(Zxi) % Use interp1(Y,X,0) to get line intercepts as Xzx
Xzx(k1) = interp1([Ydn(Zxi(k1)-1) Ydn(Zxi(k1))], [Xd(1,Zxi(k1)-1) Xd(1,Zxi(k1))], 0)
end
% PLOT ZERO-CROSSINGS ON FIGURE TO CHECK:
hold on
plot(Xzx, repmat(Yd(1,1),1,length(Xzx)), '*r')
hold off
The result:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175164/image.png)
Since you have the original data and don’t have to get it from the figure, you may want to change the variable designations from my Xd and Yd to yours. If you simply want the X-intercepts (my variable Xzx), then leave it as it is and use (or rename) Xzx as calculated here.
8 个评论
PhD_77
2014-10-8
Hi Star Strider, Thank you very much indeed. For previous t-y data it was working fine. However I have collected more data and extend t,y plot but it seems the points are not aligned well at y=0.6. Please see the new t-y data (attached). Look forward to hearing from you Many thanks for your help
Star Strider
2014-10-8
My pleasure!
That’s probably as good as it gets. Even when I expand the interpolation to ±50 indices, it doesn’t get more precise. I suspect that with slopes that extreme, you’re also encountering floating-point approximation error. (When I take the mean and standard error of the estimated zero-crossings, I get 0.60014 and 0.000183 respectively.)
My only suggestion is that you increase your sampling frequency by a factor of 10 or more, and perhaps increasing the precision of your ADC as well. That will probably improve the ability of the algorithm to approximate your 0.6 threshold with those data.
更多回答(1 个)
Sara
2014-6-26
use this function: http://www.mathworks.com/matlabcentral/fileexchange/11837-fast-and-robust-curve-intersections
with interpolation, you will likely not find the intersections.
0 个评论
另请参阅
类别
在 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!