How do I plot the plot a line using slope and one (x,y) coordinate on Matlab?
    89 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Coder Bee
 el 28 de Abr. de 2016
  
    
    
    
    
    Respondida: Karthi N
 el 6 de Ag. de 2021
            I have the slope, starting coordinates (x1,y1) and distance. Using this I need to plot a line from the known (x1,y1) coordinate. How do I do this?
0 comentarios
Respuesta aceptada
  Elias Gule
      
 el 29 de Abr. de 2016
        Let's define the slope as m; So using the equation: y = m(x-x1) + y1, we can calculate all values of y corresponding to a particular x value. Remember Matlab plot graphs by mapping point and connecting the dots. In Code we will do this.
Define the values of x for which we want to plot the graph.
x = -15:0.25:25; % Defines the domain as [-15,25] with a refinement of 0.25
Initialize m, x1,y1;
m  = 2;  % Specify your slope
x1 = -15; % Specify your starting x
y1 = -7;  % Specify your starting y
Calculate the corresponding y-values:
y = m*(x - x1) + y1;
Plot y vs x:
hPlot = plot(x,y); % plot the graph, and store line reference in a variable.
0 comentarios
Ver también
Categorías
				Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



