필터 지우기
필터 지우기

Select a multipe lines in a plot and store each lines XData and YData in an array

조회 수: 2 (최근 30일)
Thomas
Thomas 2016년 11월 23일
편집: Trang Luu 2019년 11월 23일
I'm plotting a lot of map data and I want to be able to select multiple lines to create a route by storing the X and Y co-ordinates.
I have found the following function that allows a user to select each line and then make it thicker, etc.
I've tried to modify the second function by adding
Var = num2str(h(1).XData)
but to no avail.
Does anyone know how I can implement this?
function smallTest
axes('NextPlot', 'add')
H(1) = plot(1:10, rand(1, 10), 'r');
H(2) = plot(1:10, rand(1, 10), 'b');
set(H, 'ButtonDownFcn', {@LineSelected, H})
function LineSelected(ObjectH, EventData, H)
set(ObjectH, 'LineWidth', 2.5);
set(H(H ~= ObjectH), 'LineWidth', 0.5);

답변 (1개)

KSSV
KSSV 2016년 11월 24일
function smallTest
axes('NextPlot', 'add')
H(1) = plot(1:10, rand(1, 10), 'r');
H(2) = plot(1:10, rand(1, 10), 'b');
set(H, 'ButtonDownFcn', {@LineSelected, H})
end
function LineSelected(ObjectH, EventData, H)
set(ObjectH, 'LineWidth', 2.5)
set(H(H ~= ObjectH), 'LineWidth', 0.5) ;
% Get x and y data of the highlighted lines
x = ObjectH.XData
y = ObjectH.YData
end
  댓글 수: 4
Adam
Adam 2016년 11월 24일
Use a nested function for the callback and define the variables you want to store into in the main function.
Trang Luu
Trang Luu 2019년 11월 23일
편집: Trang Luu 2019년 11월 23일
Sorry can you please explain a bit more?
I was able to add the following lines of code to save my X and Y values to my workspace, but every time I select another line on my plot, the variable would update. I would like the variable to just be added to instead of constantly replaced.
function LineSelected(ObjectH, EventData, H)
set(ObjectH, 'LineWidth', 2.5)
set(H(H ~= ObjectH), 'LineWidth', 0.5) ;
% Get x and y data of the highlighted lines
x = ObjectH.XData
y = ObjectH.YData
assignin('base','XinWorkSpace',x);
assignin('base','YinWorkSpace',y);
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by