Matlab GUI axis buttondownfnc Select points

조회 수: 3 (최근 30일)
Eddie
Eddie 2011년 7월 15일
I've got a figure with different points that are related in pairs. When clicking in one of the points I would like to change the marker of that point and also the marker of the related point.
Then when clinking in the axis instead of a point return the markers to its original.

채택된 답변

Patrick Kalita
Patrick Kalita 2011년 7월 15일
Well this sounded like a fun one, so here's what I came up with:
% Set up my data sets. Each pair of x-coordinates goes into one column of a
% 2-by-N array. Each pair of y-coordinates goes into one column of another 2-by-N
% array.
X = [ rand(1,10); rand(1,10) ];
Y = [ rand(1,10); rand(1,10) ];
% Make an axes and plot the lines. When you give PLOT two arrays like this it
% will make a separate line for each column of data.
a = axes;
p = plot(a, X, Y, 'LineStyle', 'none', 'Marker', 'o', 'MarkerSize', 15, 'Color', 'k');
% When you click on the axes, set all of the marker of all the lines.
set(a, 'ButtonDownFcn', @(src, evt) set( p, 'Marker', 'o' ) );
% When you click on a line, set the marker of just the line you clicked on.
set(p, 'ButtonDownFcn', @(src, evt) set( src, 'Marker', 's' ) );
  댓글 수: 2
Eddie
Eddie 2011년 7월 15일
It works really well. The only problem is that in my original data there were two different markers for different information. Using your method, can I plot the begining of one line with one marker and the end with another???
Thanks, for your help.
Walter Roberson
Walter Roberson 2011년 7월 15일
Not easily, no. You would have to plot the line with no markers at all, and then plot each point with the marker appropriate for it.
The "line" and "lineseries" objects are restricted to one marker type per line.

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

추가 답변 (1개)

Eddie
Eddie 2011년 7월 15일
Thank you all, Finally I manage a solution. First I plot the lines using different and big markers and then plot the lines with little point markers. Here is the code:
ax1=handles.axes1;
axes(ax1);
X=[ real(sol1(13,:)) real(sol2(13,:)) ; real(sol1(13,:))+real(sol1(1,:)) real(sol2(13,:))+real(sol2(1,:))]
Y=[ imag(sol1(13,:)) imag(sol1(13,:)) ; imag(sol1(13,:))+imag(sol1(1,:)) imag(sol1(13,:))+imag(sol2(1,:))]
p1 = plot(X(1,:),Y(1,:),'^k','MarkerSize',5,'MarkerFaceColor','k');
hold on;
p2 = plot(X(2,:),Y(2,:),'ok','MarkerSize',5,'MarkerFaceColor','k');
p = plot(ax1, X, Y, 'LineStyle', 'none', 'Marker', '.', 'Color', 'k');
axis('equal');
set(p, 'ButtonDownFcn', @(src, evt) set( src, 'Marker', '*', 'MarkerSize',10,'Color', 'r') );
set(ax1, 'ButtonDownFcn', @(src, evt) set( p, 'Marker', '.', 'Color', 'k') );
It is not very elegant; but it does the job.

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by