How to change axis of graph and interpolate data
조회 수: 6 (최근 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:
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!