Error using * (multiplication mark)

10 views (last 30 days)
Rafha Santii
Rafha Santii on 5 Jan 2018
Commented: Rafha Santii on 5 Jan 2018
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

Answers (1)

Benjamin Kraus
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]
  1 Comment
Rafha Santii
Rafha Santii on 5 Jan 2018
Dear Benjamin Kraus, thank you for considering my question.
I am still a newbie to Matlab neural networks.
I have 14 input variables that considered affect the performance of target variable. I would like to do some trial-errors by combining 8 input variables among them to find out which variables that give the most significant influence. For the first combination of 8 input variables, the learning algorithm can show the weight & the bias values. But for the other combination of 8 input variables, it can process & show the figure plots, yet it has error.
I also tried .* just like you previosly said. Yet, the command window said nothing but the same: Error using .* Matrix dimensions must agree.
size of b1 = 2 (since I use one hidden layer, 2 unit of neuron), value of N = 255

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!