GUI handles disappear after calling script
Mostrar comentarios más antiguos
I have a large GUI that updates several axes graphs in response to user input. The application utilizes a script to perform the plotting on the various axes. I have attached a smaller example that illustrates the issue. The first time I click either button, everything executes as expected. However, if I hit any button a second time I get the error:
Error using plot Parent must be a scalar graphics handle.
Error in testPlotScript (line 3) plot(testAxisView, handles.testData.x, handles.testData.y);
Error in ScriptCalledByCallbackTest>pushbutton1_Callback (line 86) testPlotScript(); ...
###################################################
Somehow, the GUI handles are disappearing.
FIRST BUTTON PUSH:#############################################
testAxisView =
Axes (axes1) with properties:
XLim: [0 1]
YLim: [0 1]
XScale: 'linear'
YScale: 'linear'
GridLineStyle: '-'
Position: [55.1429 8.2452 39.1429 17.7500]
Units: 'characters'
Show all properties
SECOND BUTTON PUSH:#############################################
testAxisView =
0×0 empty GraphicsPlaceholder array.
How do I get around this problem?
Respuesta aceptada
Más respuestas (1)
Benjamin Kraus
el 26 de Jul. de 2018
I'm having trouble running your example. I think you are missing some pieces, including the file ScriptCalledByCallbackTest.m.
Regardless, some high-level graphics commands, including plot, call newplot to prepare the figure and axes for plotting. This command inspects the NextPlot property on both the figure and the axes to determine whether to (a) delete the axes and create a new one, (b) reset the axes, (c) or add to the existing axes.
I suspect what is happening is that NextPlot is being set to replace or replacechildren which means that a call to plot will delete the existing axes.
Add this to your testPlotScript to inspect the value of NextPlot:
testAxisView = findobj('Type', 'axes', 'Tag', 'axes1')
disp(testAxisView.NextPlot)
f = ancestor(testAxisView,'figure');
disp(f.NextPlot)
plot(testAxisView, handles.testData.x, handles.testData.y);
Let us know the value of NextPlot on both on the figure and axes. I suspect those are causing the issue you are seeing.
If not, try updating the attachments to make sure all the necessary files are included. DAA_Cert_SensorModelTest.m looks like a GUIDE generated file, but I don't see the corresponding .fig file, and I don't see the ScriptCalledByCallbackTest.m that matches ScriptCalledByCallbackTest.fig. Note: You cannot rename FIG or M files generated by GUIDE without breaking the association between the two. If you want to rename the files, you need to open them in GUIDE and choose "Save As".
1 comentario
Stephen23
el 27 de Jul. de 2018
Benjamin:
I replaced my code with your suggested changes. Here is my output.
I have also included the correct .m file
I ran into the file renaming issue that you mention. I was able to work through that. The tricky part there was going into the .fig properties and changing the names there as well.
Thank you.
ScriptCalledByCallbackTest
testAxisView =
Axes (axes1) with properties:
XLim: [0 1]
YLim: [0 1]
XScale: 'linear'
YScale: 'linear'
GridLineStyle: '-'
Position: [55.1429 8.2452 39.1429 17.7500]
Units: 'characters'
Show all properties
replace
f =
Figure (figure1) with properties:
Number: []
Name: 'ScriptCalledByCallbackTest'
Color: [0.9400 0.9400 0.9400]
Position: [135.8571 37.5625 112 32.3125]
Units: 'characters'
Show all properties
add
testAxisView =
0×0 empty GraphicsPlaceholder array.
No appropriate method, property, or field 'NextPlot' for class 'matlab.graphics.GraphicsPlaceholder'.
Error in testPlotScript (line 2)
disp(testAxisView.NextPlot)
Error in ScriptCalledByCallbackTest>pushbutton3_Callback (line 100)
testPlotScript();
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in ScriptCalledByCallbackTest (line 43)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ScriptCalledByCallbackTest('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!