How can I align multiple curves on one plot to a central point?
35 ビュー (過去 30 日間)
OmartheEngineer 2023 年 1 月 3 日
コメント済み: OmartheEngineer 2023 年 1 月 10 日
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.
for ii =1:length(SNSource)
%import power data for each product
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
%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
legend('x1','x2'); title('Raw Data');
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!