How to find X and Y coordinates of maximum gap between curves?
6 views (last 30 days)
Show older comments
MP on 10 Aug 2022
Moved: per isakson on 26 Aug 2022
Please see the attached figure. In this figure, I want to find the values of X and Y coordinates where the two curve has maximum separation in Y-direction. In this figure, we can see that maximum gap is somewhere around 0.7 in the x-scale.
To do so, I simply take the subtraction of red data and blue data and obtain the gap value and corresponding X-value.
The gap value is delta Y is 6.7*10^7 and X-value is 0.027451.
However, the gap is not maximum at X = 0.027451. So, is there any way I can find the X-Y values of maximum gap between curves?
The data is also attached here with. It may not be same dataset as shown in figure, but a similar data.
I attach fig file for the same data for refrence.
Here is the code to obtain this type of plot.
But how to find maximum gap between curves?
clear; close all
X = flux1.vapa_flx_E
set(gca,'YScale','log','YTick',[10^2 10^3 10^4 10^5 10^6 10^7 10^8 10^9 10^10 10^11],'LineWidth',1.5,'FontWeight','bold',...
dif1 = rd-bl;
[val_maxdif1, idx_maxdif1] = max(dif1);
delta_y = val_maxdif1;
x1 = X(idx_maxdif1);
Any help is greatly appriciated.
Karim on 10 Aug 2022
Edited: Karim on 11 Aug 2022
It depends on what you mean with the gap, notice that you plot it on a logarithmic axis. As a result from a graphical point of view the gap seems larger at 0.7 however if you make the axis linear you will see that the gap is bigger at the small X values
% load mat files
load(websave('X' , "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1093090/X.mat" ))
% create figure
set(gca,'YScale','log','YTick',[10^2 10^3 10^4 10^5 10^6 10^7 10^8 10^9 10^10 10^11],...
title('Logarithmic Y axis')
title('Linear Y axis')
dif1 = rd-bl;
update after extra comment of the OP
here i made an attempt to identify the 'gap' that the OP looks for
dif2 = (rd-bl)./bl;
[maxGap, ixd] = max( dif2 );
maxGap_X = X(ixd);
disp(['max gap is found at X = ', num2str(maxGap_X)])
Karim on 12 Aug 2022
Thank you, I had some issues a while back because we are limited to the amount of files we can upload to the answers per day. Hence I looked a bit for an workaround.
For completness, I also use the matfile command to see which variables are inside the mat file.
More Answers (0)
Find more on Annotations 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!