Using matlab to find points on different curves and then join them up
Show older comments
Basically I have created a file which produces a graph with a number of lines on, but need to produce a curve on top. For example, the picture 2nd from bottom on this site shows what im aiming for:
https://www.e-education.psu.edu/png520/m3_p3.html
I have the lines but need to produce the dotted line.
I know the y cooridinates of where the dotted line crosses each other lines, but need to use matlab to find the x coordinates, to plot markers onto the graph and to then join them up with a line.
I've been trying things for ages but am fairly new to matlab.
Would appreciate some help, thankyou!
Answers (2)
Paulo Silva
on 23 Jan 2011
%This is how you make a line interactively using left mouse button
%you can see the coordinates of the points on the matlab command line
clf %clear a figure, comment this to plot on a existing figure
clear %clears the variables
axis([0 1 0 1]) %define you axis max and min values [xmin xmax ymin ymax]
hold on %add stuff to the axis without clearing what's there before
for n = 1:2 %choose two points
[x(n),y(n)] = ginput(1) %waits for you to click on a point on the graph
plot(x(n),y(n),'x') %mark a cross in the point you choose
s=sprintf('Point %d',n); %make the "name" of the point
text(x(n),y(n),s) %insert text Point 1 and after the Point 2
end
line(x,y,'LineStyle','--') %creates a line between two points
%line with diferent atributes from the defaults
%line(x,y,'LineStyle','--',...
%'LineWidth',4,...
%'Color','r') %creates a line between two points
Jay
on 23 Jan 2011
0 votes
1 Comment
Paulo Silva
on 23 Jan 2011
That's just a demo with functions you will need, try them and adjust the code to your needs.
Any doubt about a function just write doc followed by the name of the function in matlab command line, for example
doc line
Categories
Find more on Desktop in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!