How do i use the edit text box in a GUI to change variables in a function?

1 view (last 30 days)
function[net,tr]=test(e_epoch,e_goals,e_LR,e_hidden,e_momentum)
clc;
load data_latih;
load target_latih;
net=newff(minmax(data_latih),[e_hidden 1],{'logsig','purelin'},'traingdm');
net.trainparam.epochs=e_epoch;
net.trainparam.goal=e_goals;
net.trainparam.lr=e_LR;
net.trainparam.mc=e_momentum;
net=tr(net,data_latih,target_latih);
%trainform
function varargout = formpelatihan(varargin)
% FORMPELATIHAN MATLAB code for formpelatihan.fig
% FORMPELATIHAN, by itself, creates a new FORMPELATIHAN or raises the existing
% singleton*.
%
% H = FORMPELATIHAN returns the handle to a new FORMPELATIHAN or the handle to
% the existing singleton*.
%
% FORMPELATIHAN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FORMPELATIHAN.M with the given input arguments.
%
% FORMPELATIHAN('Property','Value',...) creates a new FORMPELATIHAN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before formpelatihan_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to formpelatihan_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 formpelatihan
% Last Modified by GUIDE v2.5 21-Jul-2018 02:26:46
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @formpelatihan_OpeningFcn, ...
'gui_OutputFcn', @formpelatihan_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 formpelatihan is made visible.
function formpelatihan_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 command line arguments to formpelatihan (see VARARGIN)
% Choose default command line output for formpelatihan
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes formpelatihan wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = formpelatihan_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;
% --- Executes on button press in beranda1.
function beranda1_Callback(hObject, eventdata, handles)
% hObject handle to beranda1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close
haldepan
% --- Executes on button press in latihdata1.
function latihdata1_Callback(hObject, eventdata, handles)
load data_latih;
e_epoch=str2num(get(handles.maxepoch,'String'));
e_goals=str2num(get(handles.targeterror,'String'));
e_LR=str2num(get(handles.learningrate,'String'));
e_hidden=str2num(get(handles.neuronhidden,'String'));
e_momentum=str2num(get(handles.momentum,'String'));
[net,tr]=test(e_epoch,e_goals,e_LR,e_hidden,e_momentum);
save('bobotjst.mat','net','tr');
% hObject handle to latihdata1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles=guidata (hObject);
% --- Executes on button press in ujidata1.
function ujidata1_Callback(hObject, eventdata, handles)
close
formpengujian
% hObject handle to ujidata1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function maxepoch1_Callback(hObject, eventdata, handles)
% hObject handle to maxepoch1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of maxepoch1 as text
% str2double(get(hObject,'String')) returns contents of maxepoch1 as a double
% --- Executes during object creation, after setting all properties.
function maxepoch1_CreateFcn(hObject, eventdata, handles)
% hObject handle to maxepoch1 (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 targeterror1_Callback(hObject, eventdata, handles)
% hObject handle to targeterror1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of targeterror1 as text
% str2double(get(hObject,'String')) returns contents of targeterror1 as a double
% --- Executes during object creation, after setting all properties.
function targeterror1_CreateFcn(hObject, eventdata, handles)
% hObject handle to targeterror1 (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 learningrate1_Callback(hObject, eventdata, handles)
% hObject handle to learningrate1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of learningrate1 as text
% str2double(get(hObject,'String')) returns contents of learningrate1 as a double
% --- Executes during object creation, after setting all properties.
function learningrate1_CreateFcn(hObject, eventdata, handles)
% hObject handle to learningrate1 (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 neuronhidden1_Callback(hObject, eventdata, handles)
% hObject handle to neuronhidden1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of neuronhidden1 as text
% str2double(get(hObject,'String')) returns contents of neuronhidden1 as a double
% --- Executes during object creation, after setting all properties.
function neuronhidden1_CreateFcn(hObject, eventdata, handles)
% hObject handle to neuronhidden1 (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 momentum1_Callback(hObject, eventdata, handles)
% hObject handle to momentum1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of momentum1 as text
% str2double(get(hObject,'String')) returns contents of momentum1 as a double
% --- Executes during object creation, after setting all properties.
function momentum1_CreateFcn(hObject, eventdata, handles)
% hObject handle to momentum1 (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
error message
Error using network/subsasgn>network_subsasgn (line 550)
NET.trainParam.epochs is not scalar.
Error in network/subsasgn (line 10)
net = network_subsasgn(net,subscripts,v,netname);
Error in test (line 7)
net.trainparam.epochs=e_epoch;
Error in formpelatihan>latihdata1_Callback (line 96)
[net,train]=test(e_epoch,e_goals,e_LR,e_hidden,e_momentum);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in formpelatihan (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)formpelatihan('latihdata1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
please help me, thanks before
  4 Comments
Stephen23
Stephen23 on 14 Aug 2018
@Ira Miranti: this is the code the defines e_epoch, which you later allocate to net.trainparam.epochs:
e_epoch=str2num(get(handles.maxepoch,'String'));
There is absolute nothing on that line that means e_epoch must be a scalar: the output of str2num can be an array of any size.
I recommend that you avoid using str2num, and always use str2double, or do your own conversion using sscanf.
Ira Miranti
Ira Miranti on 18 Aug 2018
Edited: Ira Miranti on 18 Aug 2018
Thank you for the help. training problems have been solved well. now there is a problem with the simulation. I have attached the simulation code
here the error message: Error using network/sim (line 271) Input data sizes do not match net.inputs{1}.size.
Error in formpengujian>execute_Callback (line 838) y=sim(net_keluaran,pola);
please help me again, thank you so much.

Sign in to comment.

Answers (0)

Categories

Find more on Scope Variables and Generate Names in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!