Export level along with coordinates from contour figure datatips?

조회 수: 1 (최근 30일)
I have been adding datatips to a contour plot figure which show the x & y positions along with the contour level value. When I export the datatips to the workspace, I get the x & y positions but not the level. I know I could just look up the level using those coordinates, but since my x & y axes from the plot come from separate variables it is a bit of coding to do so. Since what I want is right in front of me, it would be nice if I could get it at the same time as I export the coordinates. I found where I can change the display text, but nothing to change the exported struct. Any suggestions? Thanks.

채택된 답변

Matt Fig
Matt Fig 2011년 5월 31일
Although I think you could alter the built-in M-code to do what you want, I would probably do this instead. I called this:
Z = peaks;
[C,h] = contour(interp2(Z,4));
then I put three data-cursors on the contours. Then from the command line:
F = findall(0,'type','hggroup');
S = get(F(1:end-1),'string');
S = regexp(cat(1,S{:}),'-*\d+\.*\d+','match');
N = cellfun(@str2double,reshape([S{:}],size(S)))
N =
221 359 -2.0891
499 592 3.8319
103 591 -0.0017914
The first column contains the x coord, the second column the y coord, and the third column the level.
  댓글 수: 1
Nancy Jestel
Nancy Jestel 2011년 5월 31일
Many thanks! I'm not familiar with handle graphics groups and that looks like a good topic to learn more about. I tried the code and made a few minor modifications, primarily because my levels are in scientific notation. Everything seems to be working well. Fantastic! Here's what I ended up with:
F = findall(gcf,'type','hggroup');
S = get(F(1:end-1),'string');
SSS = regexp(cat(1,S{:}),'-*\d+\.*\d+[e]\D\d+','match');
SS = regexp(cat(1,S{:}),'-*\d+\.*\d+','match');
for i = 1:size(SS,1)
SS{i,3}=SSS{i,3};
end;
N = cellfun(@str2double,reshape([SS{:}],size(SS)));

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

추가 답변 (1개)

Patrick Kalita
Patrick Kalita 2011년 5월 31일
As far as I know you cannot customize the struct that is exported. But it does seem like a useful thing to do. I would suggest contacting tech support and ask them to make an enhancement request for it.
  댓글 수: 1
Nancy Jestel
Nancy Jestel 2011년 5월 31일
Thanks, I did put in an enhancement request, because while it looks like Matt solved my immediate problem, that does just seem like an obvious thing to have.

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

카테고리

Help CenterFile Exchange에서 2-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