To plot lines between points

2 ビュー (過去 30 日間)
Bharath Bonala
Bharath Bonala 2015 年 3 月 26 日
回答済み: Ayush 2024 年 10 月 22 日
I have a matrix
M = [a b; c d; e f]
these values are a,b,c,d,e,f are obtained from selecting random points on an image using 'getpts' command
The values are large and decimal, as i'm selecting them from an image
I need to draw(plot) 2 lines between (a,b),(c,d) and (a,b), (e,f)
need help

回答 (1 件)

Ayush
Ayush 2024 年 10 月 22 日
Hi,
To plot two lines between the points ((a, b)), ((c, d)), and ((e, f)) in MATLAB, you can use the “plot” function. Refer to an example code below for better understanding:
% Example coordinates
M = [100.5, 200.3; 150.7, 250.8; 120.9, 180.4];
% Extract points
a = M(1, 1);
b = M(1, 2);
c = M(2, 1);
d = M(2, 2);
e = M(3, 1);
f = M(3, 2);
% Plot the lines
figure; % Create a new figure window
hold on; % Hold on to plot multiple lines
% Plot line between (a, b) and (c, d)
plot([a c], [b d], 'r-', 'LineWidth', 2); % Red line with width 2
% Plot line between (a, b) and (e, f)
plot([a e], [b f], 'b-', 'LineWidth', 2); % Blue line with width 2
% Add labels and title for clarity
xlabel('X-axis');
ylabel('Y-axis');
title('Lines between Selected Points');
legend('(a,b) to (c,d)', '(a,b) to (e,f)');
% Display grid
grid on;
hold off;
For more information on the “plot” function you can refer to the below documentation:

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by