How to change axis of graph and interpolate data
6 views (last 30 days)
Show older comments
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 Comment
Star Strider
on 26 Jun 2014
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.
Accepted Answer
Star Strider
on 26 Jun 2014
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:
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 Comments
PhD_77
on 8 Oct 2014
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
on 8 Oct 2014
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.
More Answers (1)
Sara
on 26 Jun 2014
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 Comments
See Also
Categories
Find more on Interpolation 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!