I tried saving my networks(ann and ensemble)in a separate mat file and loaded that into the above mentioned code( instead of declaring them as a global variable) and that worked :)
model parameter must be a string error
조회 수: 1 (최근 30일)
이전 댓글 표시
I have trained a neural network. I am working on a gui which is supposed to get the input from user and use the network to classify it. wen I run my code it executes til sim command and displays model parameter must be a string error..
function varargout = popGUI(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @popGUI_OpeningFcn, ...
'gui_OutputFcn', @popGUI_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 popGUI is made visible.
function popGUI_OpeningFcn(hObject, eventdata, handles, varargin)
global ann
% Choose default command line output for popGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes popGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = popGUI_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
[A,B]=uigetfile('*.sdf','sdf file');
c=cd;
cd(B);
copyfile(A,'input.sdf')
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
global ann
Fig=figure('NumberTitle', 'off');
set(Fig,'Name','My program:Calculating descriptors...');
drawnow;
!mold2.exe input.sdf
D=importdata('descriptors.txt','\t',1)
Mol_no=D.data(:,1);
D.data(:,1)=[]
D.data(:,1)=[]
ain=D.data';
skin=D.data;
handles.ain=ain;
handles.skin=skin;
guidata(hObject,handles)
set(Fig,'Name','My program:Analysing structures...');
drawnow;
popup_sel_index = get(handles.popupmenu1, 'Value');
switch popup_sel_index
case 1
netin=handles.ain;
[netout]=sim(ann,netin)
A_result=round(netout);
A_result=A_result';
A_output=[Mol_no A_result]
dlmwrite('output.txt',A_output,'delimiter','\t')
case 2
S_result=svmclassify(SVMStruct,handles.skin);
S_output=[Mol_no S_result];
dlmwrite('output.txt',S_output,'delimiter','\t')
case 3
K_output=knnclassify(handles.skin,trainV,trainT);
dlmwrite('output.txt',K_output,'delimiter','\t')
case 4
netin=D.data';
[netout]=sim(ann,netin)
A_result=round(netout);
A_result=A_result';
S_result=svmclassify(SVMStruct,D.data);
K_output=knnclassify(D.data,trainV,trainT);
ensemblein=[A_result S_result K_result];
[enout]=sim(ensemble,ensemblein);
enres=round(enres);
enres=enres';
E_output=[Mol_no enres];
end
guidata(hObjects,handles);
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
%
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject, 'String', {'ANN', 'SVM', 'KNN', 'Ensemble'});
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
command = sprintf ( 'notepad %s','output.txt');
system ( command )
댓글 수: 0
채택된 답변
추가 답변 (2개)
Jan
2011년 2월 24일
You forgot to ask a question. There are multiple "sim" commands in your code and we cannot guess, which one causes the error. But you can find this out easily:
dbstop if error
The let your progran run again. Matlab will stop, when the error occurs and you can insspect the values of the variables in the command window.
I know that debugging is a hard job. But of course every programmer has to do it. Debugging is much more efficient than posting here, because your local Matlab knows exactly, where the problem is...
댓글 수: 3
Jan
2011년 2월 24일
Ok. Start as the suggested "dbstop if error". Then inspect the parameters, which are not strings, although Matlab wants some. Finally try to assure, that these parameters are strings.
Rajiv Singh
2011년 2월 25일
This usually happens when you inadvertently call the function SIM (which is /toolbox/simulink/simulink/sim) rather than the method SIM of the Neural Network's "network" object (which is toolbox/nnet/nnet/@network/sim.m). That would happen if the variable you thought represented an object among the input arguments of SIM is something else. Try putting breakpoints at places where invoke the sim method and check the input datatypes (for ann, ensemble).
Rajiv
참고 항목
카테고리
Help Center 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!