Pass variables from callbacks to custom functions in a GUI

조회 수: 5 (최근 30일)
Gabriele Rossi
Gabriele Rossi 2020년 2월 20일
댓글: Gabriele Rossi 2020년 2월 20일
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
Adam
Adam 2020년 2월 20일
Which line is giving the error? And what is stlPlotGUI? Is it one of your functions?
Gabriele Rossi
Gabriele Rossi 2020년 2월 20일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Rik
Rik 2020년 2월 20일
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
Adam
Adam 2020년 2월 20일
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 2020년 2월 20일
Perfect, thanks for the help. Thank you!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by