gui with guide into a script file
이전 댓글 표시
i have made 2 files a gui that asks whattypes of stuff and the quantities then an ok button that gets all the quantities, and i want to use this file in another m script, vut i dont know how to please help.
function fpok_Callback(hObject, eventdata, handles)
guidata(hObject,handles);
clc
% fpmcstr=string(get(handles.chkfpmc,'string'))
% fpcoystr=string(get(handles.chkfpcoy,'string'))
% fprgstr=string(get(handles.chkfprg,'string'))
% fpblkstr=string(get(handles.chkfpblk,'string'))
% fpmcbstr=string(get(handles.chkfpmcb,'string'))
% fparidstr=string(get(handles.chkfparid,'string'))
%
%
%the below is to make a struct of all the values entered by the user
fpres=struct('FlatpackMC',nan,'FlatpackCOY',nan,'FlatpackRG',nan,'FlatpackBLK',nan,'FlatpackMCB',nan,'FlatpackArid',nan)
fpmcv=get(handles.chkfpmc,'Value');%if the checkbox is checked
fpcoyv=get(handles.chkfpcoy,'Value');
fprgv=get(handles.chkfprg,'Value');
fpblkv=get(handles.chkfpblk,'Value');
fpmcbv=get(handles.chkfpmcb,'Value');
fparidv=get(handles.chkfparid,'Value');
if fpmcv==1;%if the checkbox is checked
fpmcqt1=handles.fpmcqt.String; % this calls the number entered in the edit box
fpres.FlatpackMC=str2double(fpmcqt1);% makes that number into a number
end
if fpcoyv==1;
fpcoyqt1=handles.fpcoyqt.String;
fpres.FlatpackCOY=str2double(fpcoyqt1);
end
if fprgv==1;
fprgqt1=handles.fprgqt.String;
fpres.FlatpackRG=str2double(fprgqt1);
end
if fpblkv==1;
fpblkqt1=handles.fpblkqt.String;
fpres.FlatpackBLK=str2double(fpblkqt1);
end
if fpmcbv==1;
fpmcbqt1=handles.fpmcbqt.String;
fpres.FlatpackMCB=str2double(fpmcbqt1);
end
if fparidv==1;
fparidqt1=handles.fparidqt.String;
fpres.FlatpackArid=str2double(fparidqt1);
end
handles.output=fpres
guidata(hObject,handles);
%uiresume(ancestor(hObject, 'flatpack'))
closereq()
this is the gui call back for the ok button
fpmcqt=0;fpcoyqt=0;fprgqt=0;fpblkqt=0;fpgyqt=0;fpmcbqt=0;
fp=questdlg('Flatpacks','Select','Yes','No','c');
switch fp
case 'Yes'
result=Flatpack %was told this calls the gui it does but i cant get the values
end
disp(fpres.fpmcqt)%this is just for the mc one but it runs before you can enter a value for it
this is what someone told me to do for the call back ive tried changing the fpres to the gui file name "Flatpack" and the paper name "flatpack"
댓글 수: 1
Walter Roberson
2021년 5월 31일
How does this differ in technology from the discussion at https://www.mathworks.com/matlabcentral/answers/842565-use-a-custom-made-gui-in-another-m-file?s_tid=prof_contriblnk ?
답변 (2개)
Walter Roberson
2021년 5월 31일
closereq()
Do not do that. closereq() deletes the figure, but the handles structure is stored as part of the figure, so you are deleting the saved information about what to return the caller. You need to use the uiresume() instead of closereq() .
댓글 수: 13
Joseph Catanese
2021년 5월 31일
Image Analyst
2021년 5월 31일
@Joseph Catanese, can you just attach both the entire fig file and m file with the paper clip icon? Make it easy for people to help you.
Joseph Catanese
2021년 5월 31일
편집: Joseph Catanese
2021년 5월 31일
Walter Roberson
2021년 5월 31일
You coded as
uiresume(ancestor(hObject, 'flatpack'))
but the code I posted for you before was
uiresume(ancestor(hObject, 'figure'))
Here figure is an object type. ancestor() climbs the chain of Parent of the given object until it finds a containing object whose type is the given type -- figure in this case. So given any object any number of layers down inside a figure, ancestor() with 'figure' would return the handle of the figure that the object resides inside.
Joseph Catanese
2021년 6월 1일
Joseph Catanese
2021년 6월 1일
Walter Roberson
2021년 6월 1일
You can have the Output Function delete the figure... after you have extracted the information from handles. And as I showed in the other Question, it would return a struct that you would assign to a variable and then extract the parts of.
Joseph Catanese
2021년 6월 1일
Joseph Catanese
2021년 6월 1일
편집: Joseph Catanese
2021년 6월 2일
Joseph Catanese
2021년 6월 1일
Joseph Catanese
2021년 6월 6일
Walter Roberson
2021년 6월 6일
Still waiting for the .fig that Image Analyst asked for a week ago.
Joseph Catanese
2021년 6월 11일
편집: Joseph Catanese
2021년 6월 11일
Image Analyst
2021년 5월 29일
0 개 추천
Several ways are shown in the FAQ:
Write back if none of them work for you and attach your m-file, fig file, and any files needed at runtime to launch your program.
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!