Pass variables from callbacks to custom functions in a GUI
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
el 20 de Feb. de 2020
Which line is giving the error? And what is stlPlotGUI? Is it one of your functions?
Respuestas (1)
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
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
Ver también
Categorías
Más información sobre Graphics Object Properties en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!