problem with ginput and figure userdata

4 次查看(过去 30 天)
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