how to find difference between two points on graph in matlab

I have a graph of linear equation , the pattern of this equation is such that it has a bend in its graph, I want to find the change in the values( both along x-axis & y axis) at the start & end of this bend That graph is shown below. I want to find Δx along x axis & Δy along y axis( these are shown in color lines) , Kindly guide me how can i find that change in the matlab??
Thanks; Osman

 Réponse acceptée

Without access to your data I’m guessing here, but since the minimum of x and the minimum of y define the regions you’re interested in, I suggest:
ymin_idx = find(y == min(y))
xmin_idx = find(x == min(x))
delta_x = x(xmin_idx)-x(yminidx)
delta_y = y(xmin_idx)-x(yminidx)
I don’t have your data so I can’t test this code. You may want to reverse the signs of delta_x and delta_y since I don’t know how you want to calculate them.

10 commentaires

Dear Star Strider, i am trying to explain my question again. below are two graphs these are plotted from excel data in matlab, I want to find the bend in the graph, This is the difference between the points A & B along x- axis(which is for the 1st graph is 16000-1500=14500), also find the values of point B along y-axis(which is around 400) i have around 3000 such graphs , which has different bendings , How can i prepare a program , in which the every time the graph bend, my program give me that values along x-axis & y-axis?? <<
I did my best to make this as adaptive as possible for different data.
It finds the indices of B and A (in that order). In this example, it plots the data and plots the points of interest with red + markers:
x = [400 500 16000 700 2000]; % Create data
y = [0 800 1500 4100 17000];
dx = diff([0 x]); % Take differences in ‘x’
dxsts = [mean(dx) std(dx)]; % Calculate mean and standard deviation
dxix = find(abs(dx) >= sum(dxsts)); % Adaptive threshold finds indices of extremes
xbend = x(dxix); % x-values for the bend
ybend = y(dxix); % y-values for the bend
figure(1)
plot(x, y)
hold on
plot(xbend, ybend, '+r', 'MarkerSize', 10, 'LineWidth', 1.5)
hold off
axis([0 18000 0 18000])
If this isn’t sensitive enough, change the ‘dxsts’ line to:
dxsts = [mean(dx) 0.75*std(dx)];
or something similar.
I am using these commants to plot my data.
Step 1: give the path of matlab to folder
Step 2: using this programming
figure(1); data = xlsread('jan.xlsx'); % xls or xlsx should work
x1 = data(:,1);
y1 = data(:,2);
axis([0,300000 ,0,2000]);
plot(x1,y1)
title(' Month=Jan ')
xlabel('Modified )% x-axis label
ylabel(' Height (m)')% y-axis label
Muhammad Usman
Muhammad Usman le 22 Mai 2014
Modifié(e) : Muhammad Usman le 22 Mai 2014
i have created an excel sheet with alternate columns, when i call 1st column from excel , i write x1=data(:,1) When i run your written program , it working for one graph , in the other graphs it show wrong result..
I only know the data you have provided from the plots, so ‘wrong result’ does not give me much information.
If you know that your data of interest are perhaps in the first 5 values, limit the x and y arrays to only those values. Change these lines to limit x and y to those ranges:
dx = diff(x(1:5));
dy = diff(y(1:5));
Perhaps going back to the ‘max min’ of my original Answer would work best.
The only other thing I can suggest is to change this line slightly to:
sf = 1.0;
dxsts = [mean(dx) sf*std(dx)];
and then adjust the scaling factor, ‘sf’ to be as robust as you need. I suggest adjusting ‘sf’ to be within the range of (0.5, 1.5) at the outset (I set it to 1 here to start), and if that range does not do what you want, increase or decrease it as necessary.
I did my best to make it as robust as possible with the data you provided in your plots.
Respected Star Strider,this is my excel sheet i want to plot col 1 vs , col 3 vs 4 soon on, in matlab then want to know the corresponding x & y axis values of the bend in line,
In those data, everything of interest occurs between index rows 8-11. This seems to work for ‘DeltaX’, and I suspect a similar scheme will work for ‘DeltaY’:
M = xlsread('New Microsoft Excel Worksheet.xlsx');
for k1 = 1:2:size(M,2)
figure((k1+1)/2)
plot(M(7:11,k1), M(7:11,k1+1), 'x-', 'MarkerSize', 10)
grid on
end
Xmax = max(M(8:11,1:2:end),[],1);
Xmin = min(M(8:11,2:2:end),[],1);
DeltaX = Xmax-Xmin;
It is difficult for me to figure out what you are doing with your data (I actually do not need to know), but this seems to be at least part of the solution.
Muhammad Usman
Muhammad Usman le 24 Mai 2014
Modifié(e) : Muhammad Usman le 24 Mai 2014
thanks you very much Star Strider for guideline , my good wishes are always with you.... I want to be in touch with you in future .. this is my mail id , osman.saleem4@gmail.com inbox me plz
It took me a while to figure out your data.
This should work:
M = xlsread('New Microsoft Excel Worksheet.xlsx');
X = M(9:11, 1:2:end)
Y = M(9:11, 2:2:end)
for k1 = 1:size(M,2)/2
figure(k1)
plot(X(:,k1), Y(:,k1), '-')
hold on
plot(X(1,k1), Y(1,k1), 'pr', 'MarkerSize', 10, 'MarkerFaceColor','r')
plot(X(3,k1), Y(3,k1), 'pg', 'MarkerSize', 10, 'MarkerFaceColor','g')
hold off
grid on
end
Xmax = max(X(1:3,:),[],1);
Xmin = min(X(1:3,:),[],1);
DeltaX = Xmax-Xmin
Ymax = max(Y(1:3,:),[],1);
Ymin = min(Y(1:3,:),[],1);
DeltaY = Ymax-Ymin
The information you are interested in are all between indices 9:11, so I limited my analysis to those data. This should provide the analysis you want. I cannot say that it will be robust for all your data, but it works on those you provided.
As for plotting 324 plots, your system is probably running out of memory. Rather than have them all in memory at the same time, I suggest the savefig function. Note that ‘.fig’ files also contain all the data you used to plot them (they're actually very small MATLAB scripts). It is not difficult to recover those data from the ‘.fig’ files if you need to do that. I would create them and save them individually, labeling them appropriately so you know what they represent, then look at them individually (use the openfig function for that) or in small collections so that you do not exceed your computer’s memory capacity.

Connectez-vous pour commenter.

Plus de réponses (1)

Muhammad Usman
Muhammad Usman le 22 Mai 2014
This is the second graph, You can see that it has different bend from the above graph, I want such a program which run on the line of the graph & search the bend in line & and then at these points ( like A & B) , give me the difference of x-components of A & B along x axis( like 800-250=550) & give me the upper bend like point B , y- component along y- axis( around 1700)

4 commentaires

My 3000 graphs has different bending, some time point A & B are very above from the x -axis & some time these are from the left conner of the graph?
Respected Star Strider, guide me how can i solve my problem? I shall be very thankful to you ......
Try the code in the latest comment to my Answer. It should be sensitive enough to detect the bendings.
but in this graph , it detect the bending at wrong point.

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by