필터 지우기
필터 지우기

Neural network error: 'model' parameter must be a string when calling sim(net,data)

조회 수: 3 (최근 30일)
Hello,
I have seen other people have had this problem too - http://www.mathworks.de/matlabcentral/answers/1925-model-parameter-must-be-a-string-error but am unsure how to correct so I apologize in advance only this is acting weird.
I want to save the network to a file so I can (hopefully) use it in a aspx.NET application. When the I call sim(net,data) without saving to a file then it works, when I save it to a file I get the error:
Error using nn1 (line 34)
'model' parameter must be a string
I am using R2012a and am unsure what to do. Following the advice of others in previous versions of this problem I have found the following *when loading from the file*:
>> which sim
built-in (C:\Program Files\MATLAB\R2012a\toolbox\simulink\simulink\sim)
when I *don't* load from the file I get:
K>> which sim
built-in (C:\Program Files\MATLAB\R2012a\toolbox\simulink\simulink\sim)
any help will be gratefully appreciated
Mark
clearvars -global;
a = xlsread('c:\\CS Data\\ScoringValidation1.xls');
a(isnan(a)) =0;
data = a(:, 2:size(a,2)-2);
data = data';
targets = a(:, size(a,2)-1:size(a,2));
t = targets';
net = patternnet(10)
net = train(net,data,t);
view(net)
y = net(data);
perf = perform(net,t,y)
classes = vec2ind(y)
save 'c:\\nn\\net' net
net = load('c:\\nn\\net'); % ***when I use this I get the error when calling sim(net,data1)
% test to see if it works...
data1 = [9,1];
data1(1) = 75;
data1(2) = 75;
data1(3) = 0.06;
data1(4) = 0;
data1(5) = 1;
data1(6) = 0;
data1(7) = 1;
data1(8) = 0;
data1(9) = 8;
data1 = data1'
sim(net,data1)

채택된 답변

Walter Roberson
Walter Roberson 2012년 8월 15일
Use the extended version of "which" to provide an argument:
which sim(net)
The question becomes what class "net" is when it is created, and which class it is after the load operation.
  댓글 수: 12
Mark
Mark 2012년 8월 16일
Oh forgot to mention for the newbies out there that I used matlab 2012a edition and was running in a .net 4.0 environment.
Good luck
:-)
Walter Roberson
Walter Roberson 2012년 8월 17일
Ah... I didn't realize you were deploying this. If I had, I would have suggested the %#function approach much earlier. Oh well.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Rina Blomberg
Rina Blomberg 2015년 3월 15일
편집: Rina Blomberg 2015년 3월 15일
My answer may not be related to this specific question, but it may help anyone searching for this particular error message when attempting to use the function sim() after having saved and loaded a trained neural network.
The trained network is saved as a .mat file. Eg:
save([path 'net.mat'], 'net');
If for example, this network is then loaded in another script:
net = load([path 'net.mat']);
and then one attempts the follwing code:
results = net(testdata); or results = sim(net, testdata) ;
Then MATLAB outputs the following error (respective to the function used above): Subscript indices must either be real positive integers or logicals or 'model' parameter must be a string
The reason for the error in this particular scenario is because the network has been saved in a struct array. To access the network for simulation you must write: importvariablename.savedvariablename . For example, if using the variable names from above the network must be properly accessed by writing:
results = net.net(testdata); or results = sim(net.net, testdata);

Community Treasure Hunt

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

Start Hunting!

Translated by