Error using * (multiplication mark)
10 views (last 30 days)
Show older comments
Dear All... I've been using ANN for predicting the target value by using architecture that consists of 8 input variables, one hidden layer consists of 2 neurons, and 1 output variables; (trainlm, tansig, purelin)
yn = repmat(b2,1,N) + LW*tansig( repmat(b1,1,N) + IW*xn );
So far, I could run and got the weight and bias for each layer.
Next step, I used the same network configuration (8-2-1) for other input variables and (still the same) output variables. I could run the algorithm and plot the results, yet I could not get the weight and bias for each layer. The command window said " Error using * Inner matrix dimensions must agree."
Can I get the explanation why I could not get the weight and bias, please? I need those for creating the empirical formula that represent the network.
PS: I use R2016a
0 Comments
Answers (1)
Benjamin Kraus
on 5 Jan 2018
Edited: Benjamin Kraus
on 5 Jan 2018
It would help to know the size of b1, the value of N, etc. to give a definitive answer, but I suspect the issue is that you are using * instead of .*. The standard multiplication symbol * does matrix multiplication. If you use .* you get element-by-element multiplication. For matrix multiplication the second dimension (columns) of the first matrix must equal the first dimension (rows) of the second matrix. For element-by-element multiplication the size of the two matrices must be the same (except for scalar-expansion).
For example:
A = [1;2;3];
B = [4,5,6];
C = A*B % Matrix Multiplication
% C is a [3 x 3] matrix: [4 5 6; 8 10 12; 12 15 18]
A = [1,2,3];
B = [4;5;6];
C = A*B % Matrix Multiplication
% C is a scalar value: 32
A = [1,2,3];
B = [4,5,6];
C = A.*B % Element-by-Element Multiplication
% C is a [1 x 3] vector: [4 10 18]
See Also
Categories
Find more on Define Shallow Neural Network Architectures in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!