MATLAB Answers


obtaining a wrong matrix size

Asked by Josep
on 22 Aug 2014
Latest activity Commented on by Star Strider
on 22 Aug 2014

I would like to know why I am obtaining as a result in this code, a matrix (15x1) and not a number. I am computing a test statistics equation that involves matrices products, so I am multiplying this matrix sizes:


I guess I am supposed to achieve a number, from this matrices products, but as I have said, MATLAB returns me as a solution of this equation a 15x1 matrix. Otherwise, at the end I have put the command size(T), to know the matrix size of T, and it returns me that is a 1x1 matrix (a number). Does anybody know why this two things doesn't match?

Following, here is my MATLAB code attached if you want to take a look at it

  1 Comment

The attached code also requires .xlsx workbooks, which were not attached. Attach the workbooks if you want us to try the code.


No products are associated with this question.

1 Answer

Answer by Star Strider
on 22 Aug 2014
 Accepted answer

It is difficult to read your code and I can’t run it. I ran a simulation of the matrix operation you describe, and got a scalar result as expected.

I suggest you check the sizes of the matrices in your equation. One of your vectors may actually be a matrix.


It makes the code simpler and faster to divide scalars using ‘/’ than inv.

I avoid inv where possible because the ‘\’ operator is a much more efficient and computationally stable method of multiplying by inv, although sometimes it is unavoidable. Here, inv on the first term (a scalar) is the the same as 1/(Fk(:,j)'*inv(V)*Fk(:,j)), so it makes sense to compute it as a scalar.

on 22 Aug 2014


Thanks Star Strider one more time

My pleasure!

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!