How I draw a line?
Afficher commentaires plus anciens
I have only the value of one co-ordinate(x,y) , slope(m) and constant(c). How i draw a line in matlab?
5 commentaires
madhan ravi
le 22 Nov 2018
linewidth is increased right ? then what's the problem ?
Md Ashraf
le 22 Nov 2018
Adam
le 22 Nov 2018
Tell it to plot further then. The length is determined by the values you give it - i.e. P1 and P2
Md Ashraf
le 22 Nov 2018
Adam
le 22 Nov 2018
Well, you have y = mx + c
Choose a second 'x' value, calculate the 'y' and now you have two coordinates with which to plot a line.
Réponses (2)
Geoff Hayes
le 22 Nov 2018
Md - you could use linspace to generate some points along the x-axis and then feed that into your equation to get your corresponding y values. For example, since you have one coordinate take the x (call it say x1) and do
X = linspace(x1-10, x1+10, 100);
The above will generate 100 linearly spaced elements within the interval [x1-10, x1+10]. If you want more elements, then increase this number. If you want a larger or more narrow interval, then adjust how much you add and subtract from x1.
1 commentaire
Image Analyst
le 23 Nov 2018
Use polyfit() on the coordinates in the blob. Then use polyval() to get the x (column) value at row 1, and the last row. Untested code below. Adapt/fix as needed.
[rows, columns] = find(oneBlob);
coefficients = polyfit(columns, row, 1);
x = 1 : columns;
y = polyval(coefficients, x)
% Extract only those y inside the image.
goodY = y >= 1 & y <= rows;
y = y(goodY);
x = x(goodY);
plot(x, y, 'r-', 'LineWidth', 2);
Make sure oneBlob is a binary image with only that one blob in it, not both of them.
Catégories
En savoir plus sur Signal Operations 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!

