Error using * (multiplication mark)
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Benjamin Kraus
2018-1-5
编辑:Benjamin Kraus
2018-1-5
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]
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!