Array indices must be positive integers or logical values
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, i'm doing a prediction model application deployment using App Designer.
Somehow I have the problem: "The logical indices contain a true value outside of the array bounds" in this code:
%net = network (numinput = 1, numlayers = 2,bias connect = [1; 1], inputconnect =[1; 0], layerconnect= [0 0; 1 0], output connect[0 1]);
% 1 = hidden, 2 output
%net = network;
net.numInputs.size = 5;
net.numLayers = 2;
net.layers{1}.size=22;
net.layers{2}.size=1;
%1st layer bias
net.biasConnect (1) = 1;
%2nd layer bias
net.biasConnect (2) = 1;
%net.inputconnect (i,j) = layer i has a weight coming from input j
net.inputConnect (1,1) = 1;
%net.layerconnect (i,j) = layer i has weight coming from layer j
net.layerConnect (2,1) = 1;
net.outputConnect (1) = 1;
%net.numOutputs = 1;
net.layers{1}.transferFcn = 'logsig';
net.layers{2}.transferFcn = 'purelin';
net.trainFcn = 'trainlm';
net.IW {1,1} = 3.8199 ;
net.IW {2,1} = 0.2275;
net.IW {3,1} = 2.93;
net.IW {4,1} = 1.7426;
net.IW {5,1} = 1.6334;
net.IW {1,2} = -3.0852;
net.IW {2,2} = 1.7599;
net.IW {3,2} = 2.1106;
net.IW {4,2} = -0.74244 ;
net.IW {5,2} = -2.9748;
net.IW {1,3} = -0.6235 ;
net.IW {2,3} = -2.8592 ;
net.IW {3,3} = -2.0579 ;
net.IW {4,3} = -1.8778 ;
net.IW {5,3} = -2.7531;
net.IW {1,4} = -3.2007 ;
net.IW {2,4} = -1.3089 ;
net.IW {3,4} = -0.11837 ;
net.IW {4,4} = -2.3683 ;
net.IW {5,4} = 2.8652;
net.IW {1,5} = -0.19939 ;
net.IW {2,5} = -2.5285 ;
net.IW {3,5} = -4.4598 ;
net.IW {4,5} = 0.72103 ;
net.IW {5,5} = 0.29042;
net.IW {1,6} = -1.9205 ;
net.IW {2,6} = -3.3013 ;
net.IW {3,6} = -0.89596 ;
net.IW {4,6} = -3.2171 ;
net.IW {5,6} = -0.66324;
net.IW {1,7} = -2.6722 ;
net.IW {2,7} = 4.3006 ;
net.IW {3,7} = -0.89861 ;
net.IW {4,7} = -0.1024 ;
net.IW {5,7} = -1.0142;
net.IW {1,8} = -2.4973 ;
net.IW {2,8} = -0.61173 ;
net.IW {3,8} = -1.7423 ;
net.IW {4,8} = 1.0234 ;
net.IW {5,8} = -3.9247;
net.IW {1,9} = 3.5003 ;
net.IW {2,9} = -0.41996 ;
net.IW {3,9} = 1.7603 ;
net.IW {4,9} = 1.3895 ;
net.IW {5,9} = 3.7026;
net.IW {1,10} = -1.0545;
net.IW {2,10} = 1.1846 ;
net.IW {3,10} = -0.88849 ;
net.IW {4,10} = 4.2694;
net.IW {5,10} = 2.6955;
net.IW {1,11} = 3.8669 ;
net.IW {2,11} = -1.5016 ;
net.IW {3,11} = 1.7841 ;
net.IW {4,11} = -2.4995 ;
net.IW {5,11} = 0.63348;
net.IW {1,12} = -2.7974;
net.IW {2,12} = 1.2261 ;
net.IW {3,12} = -1.9602 ;
net.IW {4,12} = -3.846 ;
net.IW {5,12} = -1.4243;
net.IW {1,13} = 3.0741 ;
net.IW {2,13} = 1.5559 ;
net.IW {3,13} = -1.6141;
net.IW {4,13} = 2.108 ;
net.IW {5,13} = 2.708;
net.IW {1,14} = 1.5992 ;
net.IW {2,14} = 3.3081 ;
net.IW {3,14} = -2.6076 ;
net.IW {4,14} = -1.6445 ;
net.IW {5,14} = -1.9568;
net.IW {1,15} = 0.64736 ;
net.IW {2,15} = -3.0578 ;
net.IW {3,15} = -0.070619;
net.IW {4,15} = 2.2834 ;
net.IW {5,15} = 1.5807;
net.IW {1,16} = 2.2939 ;
net.IW {2,16} = 2.1723 ;
net.IW {3,16} = 2.1168 ;
net.IW {4,16} = -0.60011;
net.IW {5,16} = -3.1709;
net.IW {1,17} = 2.6567 ;
net.IW {2,17} = 2.6382 ;
net.IW {3,17} = -1.7836 ;
net.IW {4,17} = -3.1082 ;
net.IW {5,17} = -1.2596;
net.IW {1,18} = -1.4172 ;
net.IW {2,18} = -3.0409 ;
net.IW {3,18} = -2.8021 ;
net.IW {4,18} = 0.56568 ;
net.IW {5,18} = -2.5439;
net.IW {1,19} = -2.5196 ;
net.IW {2,19} = 2.3752 ;
net.IW {3,19} = 2.7803 ;
net.IW {4,19} = 1.371 ;
net.IW {5,19} = 2.1838;
net.IW {1,20} = 2.8278 ;
net.IW {2,20} = 3.8288 ;
net.IW {3,20} = -1.0769 ;
net.IW {4,20} = -1.9243;
net.IW {5,20} = 0.53391;
net.IW {1,21} = -3.2572;
net.IW {2,21} = -2.6708 ;
net.IW {3,21} = 2.4495 ;
net.IW {4,21} = -0.99147;
net.IW {5,21} = -0.49714;
net.IW {1,22} = -2.1974 ;
net.IW {2,22} = -2.8659 ;
net.IW {3,22} = 0.90556 ;
net.IW {4,22} = -2.1491 ;
net.IW {5,22} = -2.5668;
net.LW {1,1} = -1.3216 ;
net.LW {2,1} = 0.39364;
net.LW {3,1} = -0.95065;
net.LW {4,1} = -0.010914;
net.LW {5,1} = -1.1996;
net.LW {6,1} = 0.22898;
net.LW {7,1} = -0.31383;
net.LW {8,1} = -0.00054546;
net.LW {9,1} = 0.91257;
net.LW {10,1} = 0.46831;
net.LW {11,1} = -0.2685;
net.LW {12,1} = 0.41957;
net.LW {13,1} = -0.0498;
net.LW {14,1} = -0.42927;
net.LW {15,1} = 0.8528;
net.LW {16,1} = -0.40204;
net.LW {17,1} = 0.29164;
net.LW {18,1} = -0.12972;
net.LW {19,1} = -0.29871;
net.LW {20,1} = 0.50154;
net.LW {21,1} = 0.11649;
net.LW {21,1} = -0.013986;
net.b{1} = [-5.0826; 4.8936; 4.47; 3.8935; -3.4336; 2.3339; 2.0869; 1.8328; -0.92511; 0.71804; -0.3738; -0.030448; 0.69374; 1.548; 2.2692; 2.3653; 2.6207;
-2.9058;-3.7841;4.4014; -5.0016; 5.4284];
net.b{2} = -0.073773;
net.numInput{5}.range = [44 50; 10 14; 12 17; 10 16; 1 6];
%func = evalin ('base','NN22_3Copy');
%func - sim(NN22_3);
Linespeed = app.LineSpeedEditField.Value;
CN = app.CNEditField.Value;
TSC1 = app.TSC1EditField.Value;
TSC2 = app.TSC2EditField.Value;
Size = app.SizeEditField.Value;
p = [Linespeed; CN; TSC1; TSC2; Size];
app.PredictedWeightEditField.Value = net(p);
The error show in the line 191 which is the last line of the coding.
Anyone familar to slove this kind of issue ?
1 Kommentar
KSSV
am 28 Apr. 2022
This line:
app.PredictedWeightEditField.Value = net(p)
is
app.PredictedWeightEditField.Value = sim(net,p)
I am not sure though.
Antworten (1)
Abhaya
am 5 Dez. 2024
Hi Veronica,
I understand that you are trying to deploy the neural network 'net' in MATLAB App Designer. However, the error message, "Array indices must be positive integers or logical values", indicates that MATLAB is treating 'net' as a structure rather than as a neural network object.
To address this, you can refer to the code given below.
net = network;
net.numInputs=1; %Only one input will be provided to the model
net.inputs{1}.size = 5; %each input will be of size 5
net.numLayers = 2;
net.layers{1}.size=22;
net.layers{2}.size=1;
net.biasConnect (1) = 1;
net.biasConnect (2) = 1;
net.inputConnect (1,1) = 1;
net.layerConnect (2,1) = 1;
net.outputConnect = [0 1];
Additionally, you should put all the input weights in net.IW{1,1}. This is because net.IW{i,j} represents the input weights from input 'i' to layer 'j'. In the case of net.IW{1,1}, it's the input weights from the first input to the first hidden layer. In this case, the size of input weights should be 22-by-5.
initW = rand([22, 5]) %put the input weights here
net.IW{1,1} = initW;
Similarly you should put all the layer weights in net.LW{2,1}, which represents weights for the connection from the first layer to the second layer.
layerW=rand([1, 22]) %put the layer weights here
net.LW{2,1} = layerW;
Once these steps are complete, you should be able to use ‘net()’ for predictions.
For more information on MATLAB ‘network’ function, please refer to the MATLAB documentation linked below.
Hope this solves the issue.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Function Approximation and Nonlinear Regression 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!