problem with ginput and figure userdata

조회 수: 4 (최근 30일)
Steve Grobler
Steve Grobler 2016년 3월 29일
댓글: Stephen23 2016년 7월 25일
In v2014b my m-file using ginput(2) worked fine. In v2015b it fails. It looks like ginput was re-written for 2015b? So I have a figure open and I have stored some data in its UserData like this:
Info.LF=LF;
Info.LMA=LMA;
Info.SPD=SPD;
Info.S = S;
Info.T = T;
Info.Mode = Mode;
Info.fname = fname;
Info.SF = SF;
set(gcf,'UserData',Info)%,'HandleVisibility','callback')
Now when I call [x,~]=ginput(2) to pick a coule of points on the graph, ginput crashes on the line 84 (switch mode) with this error message: "SWITCH expression must be a scalar or string constant. Error in ginput (line 84) switch mode"
if (isCorrectFigure(fig))
switch mode
case 'key'
char = get(fig, 'CurrentCharacter');
curUserInput = abs(get(fig, 'CurrentCharacter')); ...etc
Somehow the variable mode in ginput has been filled with my figure UserData, which I gather has happened in line 69 of ginput ie:
mode = waitForUserInput(fig);
Can anyone explain why ginput is now messing with the figure's UserData and how I might resolve this? Many thanks Steve

답변 (1개)

Jeevan Joishi
Jeevan Joishi 2016년 4월 4일
I understand that you have a figure and you have some user defined data in it. And when you try running ginput on the current figure, an error is thrown in R2015b but it did not happen in R2014b.
I tried reproducing this issue with a sample GUI that sets some data and then call ginput on a click of a button. For both R2014b and R2015b, there were no reported errors and the GUI behaved as expected.
Please have a look at the attached GUI and M-Script and leave a comment if the error is reproducible with the sample or if you can modify the sample to reproduce the error.
  댓글 수: 1
Steve Grobler
Steve Grobler 2016년 5월 11일
thanks for your reply, I've not been able to get back to this until now. I did something similar to what you had done and was unable to replicate the problem. However I've now cut down my original code to reproduce the problem : Run the attached test_gui.m and then choose the "Select test" button on the menu bar - this will load a .mat file with some variables. Then press the "test_ginput" button and try to pick somewhere in any of the axes...

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by