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"

回答 (2 件)

Walter Roberson
Walter Roberson 2021 年 5 月 31 日

1 投票

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
Joseph Catanese 2021 年 5 月 31 日
Error using uiresume (line 26)
Argument must be a Figure object.
Error in Flatpack>fpok_Callback (line
196)
uiresume(ancestor(hObject, 'flatpack'))
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Flatpack (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Flatpack('fpok_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Image Analyst
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
Joseph Catanese 2021 年 5 月 31 日
編集済み: Joseph Catanese 2021 年 5 月 31 日
the Flatpack file is the figure and at the pottom of it is the ok button with the variables im trying to use in the other code to use another script that imports time i can get those two to work togetert becaise of the save and load function.
Walter Roberson
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
Joseph Catanese 2021 年 6 月 1 日
@Walter Roberson how do i then get the number entered from the fig to run in the other script and make the ok button close the figure
Joseph Catanese
Joseph Catanese 2021 年 6 月 1 日
i havent used guides on matlab so im sorry if you're like "bruh its not that hard smh "lol i do apreciate the help though
Walter Roberson
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
Joseph Catanese 2021 年 6 月 1 日
function varargout = Flatpack(varargin)
% FLATPACK MATLAB code for Flatpack.fig
% FLATPACK, by itself, creates a new FLATPACK or raises the existing
% singleton*.
%
% H = FLATPACK returns the handle to a new FLATPACK or the handle to
% the existing singleton*.
%
% FLATPACK('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FLATPACK.M with the given input arguments.
%
% FLATPACK('Property','Value',...) creates a new FLATPACK or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Flatpack_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Flatpack_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Flatpack
% Last Modified by GUIDE v2.5 28-May-2021 20:33:16
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Flatpack_OpeningFcn, ...
'gui_OutputFcn', @Flatpack_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function Flatpack_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% uiwait(handles.flatpack);
function varargout = Flatpack_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- Executes on button press in chkfpmc.
function chkfpmc_Callback(hObject, eventdata, handles)
fpmcv=get(hObject,'Value');
if fpmcv==1
set(handles.fpmcqt,'Visible','On')
else
set(handles.fpmcqt,'Visible','Off')
end
function chkfpcoy_Callback(hObject, eventdata, handles)
fpcoyv=get(hObject,'Value');
if fpcoyv==1
set(handles.fpcoyqt,'Visible','On')
else
set(handles.fpcoyqt,'Visible','Off')
end
function chkfprg_Callback(hObject, eventdata, handles)
fprgv=get(hObject,'Value');
if fprgv==1
set(handles.fprgqt,'Visible','On')
else
set(handles.fprgqt,'Visible','Off')
end
function chkfpblk_Callback(hObject, eventdata, handles)
fpblkv=get(hObject,'Value');
if fpblkv==1
set(handles.fpblkqt,'Visible','On')
else
set(handles.fpblkqt,'Visible','Off')
end
function chkfpmcb_Callback(hObject, eventdata, handles)
fpmcbv=get(hObject,'Value');
if fpmcbv==1
set(handles.fpmcbqt,'Visible','On')
else
set(handles.fpmcbqt,'Visible','Off')
end
function chkfparid_Callback(hObject, eventdata, handles)
fparidv=get(hObject,'Value');
if fparidv==1
set(handles.fparidqt,'Visible','On')
else
set(handles.fparidqt,'Visible','Off')
end
function fpmcqt_Callback(hObject, eventdata, handles)
function fpmcqt_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function fpcoyqt_Callback(hObject, eventdata, handles)
function fpcoyqt_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function fprgqt_Callback(hObject, eventdata, handles)
function fprgqt_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function fpblkqt_Callback(hObject, eventdata, handles)
function fpblkqt_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function fpmcbqt_Callback(hObject, eventdata, handles)
function fpmcbqt_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function fparidqt_Callback(hObject, eventdata, handles)
function fparidqt_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in fpok.
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'))
%
fpres=struct('fpmcqt',nan,'fpcoyqt',nan,'fprgqt',nan,'fpblkqt',nan,'fpmcbqt',nan,'fparidqt',nan)
if get(handles.chkfpmc,'Value')
fpmcqt1=handles.fpmcqt.String;
fpres.fpmcqt=str2double(fpmcqt1)
end
if get(handles.chkfpcoy,'Value')
fpcoyqt1=handles.fpcoyqt.String;
fpres.fpcoyqt=str2double(fpcoyqt1)
end
if get(handles.chkfprg,'Value')
fprgqt1=handles.fprgqt.String;
fpres.fprgqt=str2double(fprgqt1)
end
if get(handles.chkfpblk,'Value')
fpblkqt1=handles.fpblkqt.String;
fpres.fpblkqt=str2double(fpblkqt1)
end
if get(handles.chkfpmcb,'Value')
fpmcbqt1=handles.fpmcbqt.String;
fpres.fpmcbqt=str2double(fpmcbqt1)
end
if get(handles.chkfparid,'Value')
fparidqt1=handles.fparidqt.String;
fpres.fparidqt=str2double(fparidqt1)
end
handles.output=fpres;
%guidata(hObject,handles);
uiresume(ancestor(hObject, 'figure'))
closereq()
%save(Flatpack, 'fpres.FlatpackMC')
Joseph Catanese
Joseph Catanese 2021 年 6 月 1 日
編集済み: Joseph Catanese 2021 年 6 月 2 日
%% Flatpack
fp=questdlg('Flatpacks','Select','Yes','No','c');
switch fp
case 'Yes'
fpres=Flatpack;
otherwise
fpres=struct('fpmcqt',0,'fpcoyqt',0,'fprgqt',0,'fpblkqt',0,'fpmcbqt',0,'fparidqt',0);
end
fpmcqt=fpres.fpmcqt;
fpcoyqt=fpresfpcoyqt;
fprgqt=fpres.fprgqt;
fpblkqt=fpres.fpblkqt;
fpmcbqt=fpres.fpmcbqt;
fparidqt=fpres.fparidqt;
disp(fpmcqt)
disp(fpcoyqt)
disp(fprgqt)
disp(fpblkqt)
disp(fpmcbqt)
disp(fparidqt)
Joseph Catanese
Joseph Catanese 2021 年 6 月 1 日
this is what i have right now and it displays the struct with the number but for the call to it in the script with the questdlg it runs the fpmcqt before i can enter a number in the figure
Joseph Catanese
Joseph Catanese 2021 年 6 月 6 日
Walter Roberson
Walter Roberson 2021 年 6 月 6 日
Still waiting for the .fig that Image Analyst asked for a week ago.
Joseph Catanese
Joseph Catanese 2021 年 6 月 11 日
編集済み: Joseph Catanese 2021 年 6 月 11 日
sorry didnt see that untill today heres the two files the flatpack.m is for the fig and the receiving variables is for the main script @Walter Roberson

サインインしてコメントする。

Image Analyst
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 ExchangeGraphics Object Properties についてさらに検索

製品

リリース

R2020a

質問済み:

2021 年 5 月 29 日

編集済み:

2021 年 6 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by