MATLAB: How to find a point within a curve

cell arraysfindMATLABslope

Hello to all,
How can I calculate a point (the red point) on the same curve but 500 units less than the point indicated in blue? (see graph). The pairs (x,y) of the curve are contained in a cell within an array. I tried with the code that I copy here, but I have problems with the “find" command, because I must be changing the absolute difference manually and since I have to automate the process, this is not an option for me. Thanks for your help!
w=1936 %This is an specific day and the graph shown here is the graph from this day
k = find(abs(Array_demand{w}.Volume- x_blue_point{w}+500) < 70,1)
%Find its correspondance within the curve for X (Volume)
x_red_point=Array_demand{w}.Volume(k);
%Find its correspondance within the curve for Y(Price)
y_red_point=Array_demand{w}.Price(k);

Best Answer

Try this:
% Extract the curve for X (Volume)
x = Array_demand{w}.Volume;
% Extract the curve for Y (Price)
y = Array_demand{w}.Price;
% Define blue x
bluex = 43210;
% Define red x
redx = bluex - 500
% Find index of the red x
redIndex = find(x <= redx, 1, 'last');
% Get the y value there
redy = y(redIndex)