Creating functional menu (guide)

I created a menu using guide
and I created their callbacks
For the save, I have a matrix inside a uitable (also created using guide) that I want to export .. how can I program that?
For the reset, I need all edit boxes to be blank again.. how can I program that?
thanks

4 Kommentare

Rik
Rik am 20 Mär. 2020
Have a read here and here. It will greatly improve your chances of getting an answer.
Your screenshot only tells us you have save, close and reset buttons. You should probably consider writing your GUI yourself instead of using GUIDE. See this thread for tips and examples.
MORHAF ALLABABIDI
MORHAF ALLABABIDI am 20 Mär. 2020
Bearbeitet: Rik am 20 Mär. 2020
Here is the code I am working on
function varargout = LRT(varargin)
%LRT MATLAB code file for LRT.fig
% LRT, by itself, creates a new LRT or raises the existing
% singleton*.
%
% H = LRT returns the handle to a new LRT or the handle to
% the existing singleton*.
%
% LRT('Property','Value',...) creates a new LRT using the
% given property value pairs. Unrecognized properties are passed via
% varargin to LRT_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% LRT('CALLBACK') and LRT('CALLBACK',hObject,...) call the
% local function named CALLBACK in LRT.M with the given input
% arguments.
%
% *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 LRT
% Last Modified by GUIDE v2.5 20-Mar-2020 17:34:13
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @LRT_OpeningFcn, ...
'gui_OutputFcn', @LRT_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
% End initialization code - DO NOT EDIT
% --- Executes just before LRT is made visible.
function LRT_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for LRT
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes LRT wait for user response (see UIRESUME)
% uiwait(handles.figure1);
prompt = {'Name:','Country of Residence:','Bank account number:'};
name = 'Please enter personal information';
numlines = 1;
answer = inputdlg(prompt,name,numlines);
set(handles.Sttxt_username,'String',answer{1});
set(handles.Sttxt_country,'String',answer{2});
set(handles.Sttxt_AccountNumber,'String',answer{3});
% --- Outputs from this function are returned to the command line.
function varargout = LRT_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function Edtxt_LoanAmount_Callback(hObject, eventdata, handles)
LoanAm=get(hObject,'String');
LoanAm_num=str2double(LoanAm);
handles.LoanAm_num=LoanAm_num;
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function Edtxt_LoanAmount_CreateFcn(hObject, eventdata, handles)
% hObject handle to Edtxt_LoanAmount (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Edtxt_YIR_Callback(hObject, eventdata, handles)
YIR=get(hObject,'String');
YIR_num=str2double(YIR);
handles.YIR_num=YIR_num;
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function Edtxt_YIR_CreateFcn(hObject, eventdata, handles)
% hObject handle to Edtxt_YIR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Edtxt_MP_Callback(hObject, eventdata, handles)
MP=get(hObject,'String');
MP_num=str2double(MP);
handles.MP_num=MP_num;
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function Edtxt_MP_CreateFcn(hObject, eventdata, handles)
% hObject handle to Edtxt_MP (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in PB_Calculate.
function PB_Calculate_Callback(hObject, eventdata, handles)
LoanAm_num=handles.LoanAm_num;
YIR_num=handles.YIR_num;
MP_num=handles.MP_num;
interest = YIR_num/100;
k = 1;
i = 1;
Monthly_I = (LoanAm_num * interest)/12;
I_LoanAm = LoanAm_num;
if (LoanAm_num < 5000)
f = warndlg('Loan amount is too low, We only offer loans of upwards of 5000','Warning');
end
if (MP_num < Monthly_I)
f = errordlg('Monthly Payment is lower than the interest rate','Error');
end
if (LoanAm_num > 999999999)
f = warndlg('Loan amount is too high, We only offer loans of lower than 999999999','Warning');
end
if (YIR_num < 1.5)
f = errordlg('Our minimum Yearly Interest rate is 1.5%','Error');
end
if (MP_num < 0)
f = errordlg('Monthly Payment cant be Below 0','Error');
end
while (YIR_num >= 1.5) && (I_LoanAm >= 5000) && (MP_num > Monthly_I)
x(i,k) = LoanAm_num;
k = k + 1;
x(i,k) = MP_num;
k = k + 1;
x(i,k) = (LoanAm_num * interest)/12;
Monthly_I = x(i,k);
k = k + 1;
x(i,k) = MP_num - Monthly_I;
principal = x(i,k);
k = k+1;
x(i,k) = LoanAm_num - principal;
Endingbalance = x(i,k);
LoanAm_num = Endingbalance;
i = i + 1;
k = 1;
if Endingbalance <= MP_num
x(i,1) = Endingbalance;
x(i,2) = Endingbalance;
x(i,3) = 0;
x(i,4) = Endingbalance;
x(i,5) = 0;
set(handles.table_LRT,'Data',x);
break;
end
end
function Menu_File_Callback(hObject, eventdata, handles)
% hObject handle to edit_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function Reset_menu_Callback(hObject, eventdata, handles)
% hObject handle to edit_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function Menu_Save_Callback(hObject, eventdata, handles)
% hObject handle to tofile_menu_item (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
MORHAF ALLABABIDI
MORHAF ALLABABIDI am 20 Mär. 2020
I need to get the reset and save to work.. but I can't find any help on that
Rik
Rik am 20 Mär. 2020
Isn't a reset just closing and opening your GUI? (unless you only want to empty some of your components, in which case you could either create a separate function that creates them, or a separate function that will clear the contents, whatever that means for your context) And what variable do you need to save?
I sugest you move away from GUIDE. As you have noticed it creates a wall of code that nobody wants to dig through, and you still need the fig file to run it properly.
This time I'll edit your code for you. Next time, please use the tools explained on this page to make your comments more readable.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Update figure-Based Apps finden Sie in Hilfe-Center und File Exchange

Produkte

Tags

Gefragt:

am 20 Mär. 2020

Bearbeitet:

Rik
am 20 Mär. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by