Neural network error: 'model' parameter must be a string when calling sim(net,data)
2 次查看(过去 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)
0 个评论
采纳的回答
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 个评论
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
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);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!