フィルターのクリア

Free hand drawing in Matlab with output is XY coordinate of trajectory.

21 ビュー (過去 30 日間)
tien dang
tien dang 2018 年 11 月 14 日
回答済み: Peter Seibold 2023 年 8 月 29 日
How i can free draw any trajcetory with the output is the XY coordinate of trajectory like in the picture. I just try to find in the answer in form but did no find any answers satisfiing the requirement. Tks you for any answer. 2.png

採用された回答

Adam Danz
Adam Danz 2018 年 11 月 14 日
編集済み: Adam Danz 2018 年 11 月 14 日
This might be what you're looking for. ginput() allows you to click on a graph as many times as you'd like and it returns a 2-column matrix of x,y coordnates where you clicked.
Demo 1
Run this, click around the axes, press Enter to see where you clicked. xy will be the coordinate of your clicks.
figure
xy = ginput(); % now click as many coordinates as you'd like then press Enter when finished.
plot(xy(:,1), xy(:,2), 'bo', 'MarkerSize', 8, 'MarkerFaceColor', 'b');
Demo 2
This version plots as you click instead of plotting at the end. Press Enter to stop. xy will be the coordinate of your most recent click.
figure
axh = axes;
hold(axh, 'on')
xy = [0,0];
while ~isempty(xy)
xy = ginput(1);
if ~isempty(xy)
plot(axh, xy(1), xy(2), 'bo', 'MarkerSize', 8, 'MarkerFaceColor', 'b');
end
end

その他の回答 (1 件)

Peter Seibold
Peter Seibold 2023 年 8 月 29 日
Another demo that stores the xy values:
disp('click inside figure')
disp('hit "return" button to finish')
figure(1)
clf
axh = axes;
hold(axh, 'on')
xlim([0,2])% change the limits to your requirements
ylim([0,1])% change the limits to your requirements
grid on
xyTemp = [0,0];
xy=xyTemp;
k=0;
while ~isempty(xyTemp)
xyTemp = ginput(1);
if ~isempty(xyTemp)
plot(axh, xyTemp(1), xyTemp(2), 'bo', 'MarkerSize', 6, 'MarkerFaceColor', 'b');
k=k+1;
xy(k,:)=xyTemp;
end
end
hold(axh, 'off')
figure(2)
plot(xy(:,1),xy(:,2),'.-b')
grid on
disp('finished')
disp('Previous to a second run you may resize the figure to your requirements')

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by