Hello Experts, I have code in which it gives error of "Error of inner matrix dimension". i have checked many of answers in the group asked by others and tried but it is not getting removed. Help me to remove this error.If i comment that line of code it runs.Error is not in "main.m" program but it is in "trainRELM.m" line no 87. While i run the main.m it gives error Error using * Inner matrix dimensions must agree.
Error in trainRELM (line 87)
w = (H'*H+l1*eye(nh,nh))\(H'*Data.y);
is main cause of error
Error in Main (line 47)
LR2 = trainRELM(DataTG,Params);
I have attached the code and dataset.

 Akzeptierte Antwort

dpb
dpb am 14 Apr. 2017

0 Stimmen

You have two matrix multiplications in the offending line H+l1*eye(nh,nh))\(H'*Data.y);
So, the problem is one of the following:
  1. Variable i1 is a not square(*), or
  2. size(H',2) ~= size(Data.y,1)(*), or
  3. didn't intend to use matrix multiplication but element-wise which is the "dot" operator ".*"
Don't know which of the above is the actual case nor necessarily the answer you need as didn't try to read the code but looking through your algorithm for the intended result ensuring that you can actually perform a legal matrix multiplication if that's what is wanted or if it is computation in the numerator/denominator of the expression that is supposed to be element-by-element, then fix the operator to do that instead.
() Matrix multiplication requires A*B have dimensions such that are [m x n][n x q] with result of [m x q].

7 Kommentare

tejasvee
tejasvee am 16 Apr. 2017
Thank you
tejasvee
tejasvee am 16 Apr. 2017
w = (H'*H+l1*eye(nh,nh))\(H'*Data.y); In this if i have defined nh= 100 and want to create identity matrix of size 100*100 eye(nh,nh) is not working to create 100*100 matrix it is of 1*1 matrix. i tried a lot to create it. because my dimension of H is 297*100 so compatible dimension of eye should be 100*100.
dpb
dpb am 16 Apr. 2017
Bearbeitet: dpb am 16 Apr. 2017
for loop = 10: 1:200
Params.nh =loop;
...
LR2 = trainRELM(DataTG,Params);
...
In trainRELM you have
function LearningResults=trainRELM(Data,Params)
...
% use default settings
if (nargin == 1)
Params.nh = 100;
...
else
...
end
nh = Params.nh;
and you called it with two arguments so the first clause is never executed.
Hence, nh is NOT defined as 100 but has the same value as the loop index loop which starts at 10 first pass (so it's not 1x1, either...at least in the posted code).
Set a breakpoint in the editor and use the debugger to see...
tejasvee
tejasvee am 16 Apr. 2017
Bearbeitet: dpb am 16 Apr. 2017
Thankyou sir to figure out that, i was also not seeing that ,but help me as in
w = (H'*H+l1*eye(nh,nh))\(H'*Data.y);
H has dimension 303*100 so for matrix multiplication eye(nh,nh) should be of 100*n for compatible matrix multiplication. now how can i complete this above equation for results of program.
dpb
dpb am 16 Apr. 2017
Either
  1. don't pass the params second argument to the function and let it use the defaults or
  2. set the value in the params structure to 100 instead of the loop variable that you're now doing. I don't know why you're doing that, anyway--doesn't seem to make much sense???
tejasvee
tejasvee am 17 Apr. 2017
Thankyou Sir for reply, I figured out that there is error in inner matrix dimension due to (H'*Data.y); in the below equation as H' is of dimension 100*303 and Data.y is of 0. i checked the size of Data.y w = (H'*H+l1*eye(nh,nh))\(H'*Data.y); But i can't understand how to make it of dimension 303*n as Data.y is is the vector of labels, either regression or classification labels (+1,-1) then how it could be of dimension 303*n or something else.
tejasvee
tejasvee am 18 Apr. 2017
Sir in the last query , i asked you for data.y is not compatible for matrix multiplication. As it is vector of labels, either regression or classification labels (+1,-1) so i converted it to matrix by using Data.y=vec2mat(Data.y,297) to make it compatible but again there is same error of inner matrix dimension. What should i do to make it compatible. https://in.mathworks.com/matlabcentral/answers/335348-error-in-the-code-not-getting-removed

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 14 Apr. 2017

Kommentiert:

am 18 Apr. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by