Pass variables from callbacks to custom functions in a GUI

4 visualizaciones (últimos 30 días)
Gabriele Rossi
Gabriele Rossi el 20 de Feb. de 2020
Comentada: Gabriele Rossi el 20 de Feb. de 2020
I created a gui with two buttons that allow you to load the stl files and record the mesh on axes. I wanted to create a custom function to be called every time the changes to the mesh are displayed in order to refresh the display. I'm having trouble passing the loaded data to the function, when I run it I get the error message:
"Object must be a figure or one of its child objects"
Can anyone tell me what am I wrong? Thank you!
This is the callbacks of the button:
function OpenSTLfileButtonPushed(app, event)
[file, pathToFile] = uigetfile({'*.*','All Files'},'Select .STL File');
[f,v,N] = stlread(strcat(pathToFile,file));
v_min_x = min(v(:,1));
v_min_y = min(v(:,2));
v_min_z = min(v(:,3));
v(:,1) = v(:,1) - v_min_x;
v(:,2) = v(:,2) - v_min_y;
v(:,3) = v(:,3) - v_min_z;
[f2,v2] = remove_duplicate_vertex(f,v);
edgeUnici = UniqueEdgeSearch(f2);
handles.f2 = f2;
handles.v2 = v2;
guidata(app, handles);
refresh(app, handles);
end
And and this is the custom function:
function refresh(app,handles)
disp("ciao");
f2 = handles.f2;
v2 = handles.v2;
stlPlotGUI(v2,f2,'C','k',app.UIAxes);
hold(app.UIAxes, 'on' );
end
  2 comentarios
Adam
Adam el 20 de Feb. de 2020
Which line is giving the error? And what is stlPlotGUI? Is it one of your functions?
Gabriele Rossi
Gabriele Rossi el 20 de Feb. de 2020
yes, stlPlotGUI is one of my function. This is a error message:
Error using guidata (line 87)
Object must be a figure or one of its child objects.
Error in Applicazione/OpenSTLfileButtonPushed (line 67)
guidata(app, handles);
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.

Iniciar sesión para comentar.

Respuestas (1)

Rik
Rik el 20 de Feb. de 2020
I'm going to assume the error occurs at this line
guidata(app, handles);
You are mixing a GUIDE-style GUI syntax with an AppDesigner GUI. The guidata function stores data with a figure, which you don't really need when using AppDesigner. You can store your data in the app properties, or use the handle to your uifigure as the first input to guidata.
  3 comentarios
Adam
Adam el 20 de Feb. de 2020
app.f2 = f2;
app.v2 = v2;
Then add a properties block to your app (there is a button somewhere up in the top left I think to do this, I haven't used it for a while so can't remember) that should look something like this:
properties( access = private )
f2;
v2;
end
Gabriele Rossi
Gabriele Rossi el 20 de Feb. de 2020
Perfect, thanks for the help. Thank you!

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Properties en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by