Select a multipe lines in a plot and store each lines XData and YData in an array
3 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
回答(1 个)
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
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
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 Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!