how to solve matlab NN toolbox error not enough inputs arguments ?

3 views (last 30 days)
am trying to create a neural network function so I can deploy it into c or standalone application but always gives me the error of not enough inputs arguments, so anyone can tell me how to modify the code to reuse the network into c# application so that I can input new data with close values the one NN trained on and give me the predicated output?
I can see from the code that NN used static input values which i donot want that, I want to input new values so get me the predicated values here the code
function [Y,Xf,Af] = myNeuralNetworkFunction(X,~,~)
%MYNEURALNETWORKFUNCTION neural network simulation function.
%
% Generated by Neural Network Toolbox function genFunction, 09-Jun-2016 00:57:04.
%
% [Y] = myNeuralNetworkFunction(X,~,~) takes these arguments:
%
% X = 1xTS cell, 1 inputs over TS timsteps
% Each X{1,ts} = 17xQ matrix, input #1 at timestep ts.
%
% and returns:
% Y = 1xTS cell of 1 outputs over TS timesteps.
% Each Y{1,ts} = 2xQ matrix, output #1 at timestep ts.
%
% where Q is number of samples (or series) and TS is the number of timesteps.
%#ok<*RPMT0>
% ===== NEURAL NETWORK CONSTANTS =====
% Input 1
x1_step1_xoffset = [-4.47310297921142;-1.85909127280455;-0.625185261929035;-0.0256816777690774;-0.0195677809165305;-1610.49160469576;-0.54405239197115;0.0330894463468129;0.0925928354776858;-38.9174335249943;0.0115926458333333;0;-7.29677389508369;-30.2898596607645;-8.5438496316238;-0.954894582712266;-0.63800797045558];
x1_step1_gain = [0.376884177299197;0.904155632977379;1.99664742190132;0.00204434510902907;0.66932770710513;0.00110445792275355;1.96096305698989;2.09417163481175;0.0386534069057506;0.0203042926537549;0.0381419435948444;0.330021059677786;0.0119800709435464;0.0571064479615686;0.176139539943952;1.04824297933799;2.15255884421271];
x1_step1_ymin = -1;
% Layer 1
b1 = [-1.6287944352627952;-1.3121026849925292;-0.60191957055138579;0.487298568430444;0.13938180674323636;0.10670751307356031;0.52643945571453488;-0.91965518646042987;-0.97676440458818725;-1.476904271655662];
IW1_1 = [0.31475682662514637 -0.55190174834793049 -0.42156693589351918 -0.22183062340456197 -0.035534636566275077 -0.2022885567441095 -0.64524298888812393 -0.47823490828019077 0.27003700278476067 -0.28753502444264617 0.065402480594795309 0.23429540878934721 0.52356279197357769 -0.73125433409301532 -0.092331938004903344 0.39983720605096101 -0.11551449421774322;0.57541047347605034 -0.33116120681199568 0.20587039936150242 0.38231551424008819 0.38798821702013409 0.095161317522587913 0.079391500774945126 0.24754028167973643 -0.062913061713969112 -0.50862773156259067 0.75669280727225607 0.41662007349012314 0.038826463034962691 0.29961608689868829 -0.62605667693572264 -0.1493482692752727 0.40951017839092585;0.36576539245059542 0.015881607958972008 -0.18715745582027679 0.096494486030484536 -0.46111998998462161 -0.33448611653743193 0.31477894119350214 -0.14388184062333748 0.45488179327199185 0.57730157661503345 -0.78446114044969883 0.36587998149695788 -0.3230741960067226 -0.17643032202374423 -0.25312123490482441 0.67455355511382376 0.57882532795695996;0.004176679254506409 -0.13346038141224748 0.35157330226312539 -0.077087506474782352 0.52531179723670363 0.17290709845428409 0.0350597603396599 -0.069319871739868935 0.74981718756741045 0.28223182462947788 -1.0111984522006987 0.75693709021503386 0.40528769942079135 -0.11709386077970714 -0.38652038228964258 0.36927365370598159 -0.32149981238975733;-0.20208342563812387 -0.31250407213860126 0.50899976381262491 0.58889272841418783 0.055944109990358662 -0.51269801351537014 -0.11777804570733025 0.76275317618237171 0.22617708851963658 0.011463018547584107 -1.3652514123628503 -0.49031673312852114 0.48295229475661966 0.33960215540504712 -0.60749029948714928 -0.026195678404673822 0.84285681231842069;0.14999755093166955 0.42490579392760841 -0.50192647281120251 0.013304982139845234 -0.53571015651356646 0.45839202895998182 0.21346473018182782 -0.0044197416378180454 0.2573817247046894 0.20125537300429877 -0.63152816775746545 -0.44493203725027131 0.11436684823781258 -0.24010683645431755 -0.4361773990240147 -0.35094087925395517 0.68916989187684274;0.3004867858311297 0.14110993238763953 -0.58136885816288386 0.64416267529268278 -0.68831751187980472 -0.36343267067768725 0.19842035849616763 -0.43138721772403893 -0.028459728202367349 0.063042134841801906 0.11183121342688751 0.3609119325036681 -0.30513599524008961 0.36571211870230447 0.81108564741413713 0.41027981337816127 -0.14805793184402113;0.069039444312882822 0.50889648703440482 -0.27304435399374111 -0.31801084208171659 0.37035368197814889 0.25978426618619122 0.18273467775248045 0.7554193466721244 0.28649280746896283 0.20278284409102865 -0.22960916043174481 -0.50218978381547297 -0.37236755989399561 -0.10926785534587687 -0.26014291682281837 0.73949202053846685 0.63089597971180522;-0.44014643974849493 0.40589090434285091 0.43150394983539125 -0.2252332463847859 -0.18210739898422665 -0.42371672912768271 0.32519962385251427 0.49257031509196164 0.67102785627568662 0.017009760757859548 -0.68215579700405193 -0.20594143413061902 -0.011078194044411124 0.50282442561852259 0.82557475467052654 -0.20504351839680396 0.32750194774822206;-0.31620183461853563 0.7785836008234519 0.50466110542326792 -0.28893622625602433 -0.56507901370931912 -0.19606219707093817 0.65984455526730212 -0.20683072411305289 -0.52961373745628626 0.31154629844779641 0.39608294171726377 -0.076214703420833224 -0.4791647378449474 0.38736825608299197 -0.047618833883243429 0.32262338803471369 -0.4917239715463389];
% Layer 2
b2 = [0.33334709234046916;0.46302926096605324];
LW2_1 = [-0.74042034519307054 0.52105840191696873 0.61268201833229696 0.15547518738222196 0.60517696635451035 0.59633986977774511 -0.5295815132260151 -0.41114225981520613 0.84675280396463115 0.064356504481856758;-0.045944334814211681 0.62752066608672508 -0.39570746764525128 -0.9074455750996071 -2.1091803800915065 -0.24868122199804693 -0.10098602475838322 -1.18369300241904 -0.024208400676846799 1.188195630141925];
% ===== SIMULATION ========
% Format Input Arguments
isCellX = iscell(X);
if ~isCellX, X = {X}; end;
% Dimensions
TS = size(X,2); % timesteps
if ~isempty(X)
Q = size(X{1},2); % samples/series
else
Q = 0;
end
% Allocate Outputs
Y = cell(1,TS);
% Time loop
for ts=1:TS
% Input 1
Xp1 = mapminmax_apply(X{1,ts},x1_step1_gain,x1_step1_xoffset,x1_step1_ymin);
% Layer 1
a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*Xp1);
% Layer 2
a2 = softmax_apply(repmat(b2,1,Q) + LW2_1*a1);
% Output 1
Y{1,ts} = a2;
end
% Final Delay States
Xf = cell(1,0);
Af = cell(2,0);
% Format Output Arguments
if ~isCellX, Y = cell2mat(Y); end
end
% ===== MODULE FUNCTIONS ========
% Map Minimum and Maximum Input Processing Function
function y = mapminmax_apply(x,settings_gain,settings_xoffset,settings_ymin)
y = bsxfun(@minus,x,settings_xoffset);
y = bsxfun(@times,y,settings_gain);
y = bsxfun(@plus,y,settings_ymin);
end
% Competitive Soft Transfer Function
function a = softmax_apply(n)
nmax = max(n,[],1);
n = bsxfun(@minus,n,nmax);
numer = exp(n);
denom = sum(numer,1);
denom(denom == 0) = 1;
a = bsxfun(@rdivide,numer,denom);
end
% Sigmoid Symmetric Transfer Function
function a = tansig_apply(n)
a = 2 ./ (1 + exp(-2*n)) - 1;
end

Answers (1)

Walter Roberson
Walter Roberson on 9 Jun 2016
How are you invoking it? You need to call it, passing in values. For example,
myNeuralNetworkFunction(rand(17,30))
The first dimension of the input needs to be 17 to match your code.
  9 Comments
Walter Roberson
Walter Roberson on 12 Jun 2016
You cannot run that code by pressing Run. You need to supply arguments to it. I showed an example,
myNeuralNetworkFunction(rand(17,30))
Inside Excel you would need to make a VBA call to MLPutMatrix to grab your data from the spreadsheet and assign it as a variable named X in MATLAB. Then in the VBA, you would use
=MLEvalString("[Y, Xf, Af] = myNeuralNetworkFunction(X)")
Then in VBA you would use MLGetMatrix calls to retrieve the variables Y, Xf, and Af, and put them in appropriate places in your worksheet.
essam
essam on 16 Jun 2016
thanks for answer, but I found something when I run the code myNeuralNetworkFunction(0.5) with One input it gives me the answer, but what I see wrong in the code, that i only have one input (0 or 1) and 17 inputs but in the matlab code generated by NNtoolbox gives me
function [Y,Xf,Af] = myNeuralNetworkFunction(X,~,~)
where 3 output and only one input why that? did I import data wrong? I imported them in matrix 17x200 double ( 200 case ) and output (1x200) double

Sign in to comment.

Categories

Find more on Data Import from MATLAB 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!