How can I align multiple curves on one plot to a central point?
35 ビュー (過去 30 日間)
表示 古いコメント
I am plotting several curves on a single plot as part of several test points for a tool I am developing. In the final step, I overlay all the curves on top of one another for a visual display. As you can see all the plots are shifted relative to one another. How can i go about aligning these cruves so that similar features align? Keep in mind they will not perfectly align. What I am looking at was something like the pdf file (done in excel). I thought I could find the center point for the flat portion of the curve (already have those points defined as part of the test) and somehow make all 15 curves center point align on the curve. Any ideas are appreciated.
Edit:Updated question and attachments based on feedback.
Thanks
Sample Code:
for ii =1:length(SNSource)
%import power data for each product
ScatterData=importdata(cell2mat(SNSource(ii)))
plot(ScatterData(:,1),ScatterData(:,2))
title('ScatterData')
hold on
xlabel('Distance mm')
ylabel('Power')
end
0 件のコメント
採用された回答
Image Analyst
2023 年 1 月 3 日
How about if you found where it crossed 0.001 on both sides, compute the middle from that, and then compute the delta x from there to the desired, common x center point and add it to the x vector for each curve?
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
その他の回答 (1 件)
William Rose
2023 年 1 月 3 日
It would help if you would attach the actual data as a .mat file or a text file for easy import.
Your choce of a linear y-axis for one plot, and a logarithmic y-axis for the other, makes it more difficult to compare the images.
The first image file attached appears to be the one from Excel, but I am not positive, and file names and plot titles do not make it obvious. I recommend that in the future you not use terms like "the second picture", since the order of file attachment may not be what you expect.
It looks to me like you have already aligned the plots pretty well in the Excel plot. When you say you want to align the plots better, are you only doing a horizontal shift? Or do you also want to do a vertical shift? Would you allow shrinking or stretching of the horizontal or vertical scale to improve the alignment?
I will assume you just want to slide the curves horizontally, without steching or shrinkking. Here is an example of how you can use the cross correlation to adjust the horizontal position, using simulated data:
%create simulated data
N=100;
t1=1:N; t2=t1;
x1=10*[zeros(1,35),ones(1,20),zeros(1,45)]+rand(1,N);
x2=10*[zeros(1,45),ones(1,20),zeros(1,35)]+rand(1,N);
%find the optimal alignment for the simulated data
[~,idx]=max(xcorr(x1,x2)); %idx=index where cross correlation is maximum
t2adj=t2+idx-N; %shift the time base for x2
%plot the results
subplot(211); plot(t1,x1,'-r.',t2,x2,'-b.');
legend('x1','x2'); title('Raw Data');
subplot(212); plot(t1,x1,'-r.',t2adj,x2,'-b.');
legend('x1','x2'); title('Adjusted Data');
This works nicely. You can do it again for x1 and x3, x1 and x4, etc. Good luck!
参考
カテゴリ
Find more on Convert Image Type 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!