problem with ginput and figure userdata
2 次查看(过去 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
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Exploration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!