Undefined function or variable in my simple project
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
inggrid kinanti
am 3 Jul. 2020
Kommentiert: Walter Roberson
am 20 Jul. 2020
Hi...
I tried to develop my simple project after studying matlab. but I have a problem that is when I press the process button (btnTrain), an error like this appears;
1) Undefined function or variable 'addressfile'.
2.) Error in try 01> btnTrain_Callback training_ data = file address (:, 1: 5);
Could you help me correct my code for that?
Please help me to correct my error code,
this is my code :
% --- Executes on button press in btnBrowse.
function btnBrowse_Callback(hObject, eventdata, handles)
proyek=guidata(gcbo);
[namafile,direktori]=uigetfile({'*.xls;*.xlsx','file excel(*.xls,*.xlsx)';'*.*','semua file(*.*)'},'buka file Excel');
alamatfile=fullfile(direktori,namafile);
xlRange='A1:E32';
set(handles.btnBrowse,'String','alamatfile');
[a,b,c]=xlsread(alamatfile,xlRange);
bar=size(c,1);
col=size(c,2);
rnames=linspace(1,bar,bar);
data=c(:,1:col)
data_latih=alamatfile(:,1:5);
target_latih=alamatfile(:,6)';
[m,n]=size(data_latih);
set(handles.tabel1,'Data',data);
guidata(hObject,handles);
% --- Executes on button press in btnTrain.
function btnTrain_Callback(hObject, eventdata, handles)
data_latih=alamatfile(:,1:5);
net=newff(minmax(data_latih),[30 20 20 20 1],{'tansig','logsig','logsig','logsig','purelin'},'traingdx');
learning_rate=str2double(get(handles.edit11,'String'));
epoch=str2double(get(handles.edit12,'String'));
goal=str2double(get(handles.edit13,'String'));
show=str2double(get(handles.edit14,'String'));
net.performFcn = 'mse';
net.trainParam.showWindow = true;
net.trainParam.showCommandLine = false;
net.trainParam.show = show;
net.trainParam.epochs = epoch;
net.trainParam.time = inf;
net.trainParam.goal = goal;
net.trainParam.min_grad = 1e-09;
net.trainParam.max_fail = 3000;
net.trainParam.lr = learning_rate;
net.trainParam.mc=0.95;
[net_keluaran,tr,Y,E]= train(net,data_latih,target_latih);
bobot_input = net_keluaran.IW{1,1};
bobot_bias_input = net_keluaran.b{1,1};
bobot_lapisan1 = net_keluaran.LW{2,1};
bobot_bias_lapisan1= net_keluaran.b{2,1};
bobot_lapisan2 = net_keluaran.LW{3,1};
bobot_bias_lapisan2= net_keluaran.b{3,1};
bobot_lapisan3 = net_keluaran.LW{4,1};
bobot_bias_lapisan3= net_keluaran.b{4,1};
bobot_lapisan4 = net_keluaran.LW{5,1};
bobot_bias_lapisan4= net_keluaran.b{5,1};
jumlah_iterasi = tr.num_epochs;
nilai_keluaran = Y;
nilai_error = E;
error_MSE = (1/n)*sum(nilai_error.^2);
save net.mat net_keluaran
% Hasil prediksi
hasil_latih = sim(net_keluaran,data_latih);
max_data = max(max('Data'));
min_data = min(min('Data'));
hasil_latih = ((hasil_latih-0.1)*(max_data-min_data)/0.8)+min_data;
set(handles.tabel_output,'Data',hasil_latih);
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 3 Jul. 2020
Your code only has alamatfile as a local variable to btnBrowse_Callback . You are not saving it for use in other functions.
http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
alamatfile=fullfile(direktori,namafile);
alamatfile is going to be a file name -- a character vector.
[a,b,c]=xlsread(alamatfile,xlRange);
You read the file contents into a, b, c. Meanwhile, alamatfile is going to continue to be the character vector that is the file name.
data_latih=alamatfile(:,1:5);
The character vector has one row, so using : as the first subscript refers to that one row, which is okay. Then you take the first 5 characters of the file name and assign them to data_latih .
target_latih=alamatfile(:,6)';
target_latih is going to become the 6th character of the file name only. As it will be a scalar, the transpose at the end of the line is not doing anything useful there.
[m,n]=size(data_latih);
We established above that data_latih is going to be a 1 x 5 character vector because you extract it from the file name. So m will become 1 and n will become 5.
You do not do anything with data_latih or target_latih or m or n before you return from the function, so it is not clear why you bother calculating them.
function btnTrain_Callback(hObject, eventdata, handles)
data_latih=alamatfile(:,1:5);
If you had managed to share alamatfile from the other function, then it would be the character vector that is the file name, and data_latih would become the first 5 characters of that.
net=newff(minmax(data_latih),[30 20 20 20 1],{'tansig','logsig','logsig','logsig','purelin'},'traingdx');
so you take the minmax of the 5 characters in data_latih . But that is an error, because minmax() must be applied to a numeric array or a cell array.
5 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!