What does it mean [X,T]=MATRIX?

568 Views Asked by At

I'm starting to study this example but I'm not understanding the matrix operation on matlab:

Whe it does [X,T] = prprob; it will copy the predefined 26x35 matrix prprog to X and a identity matrix with less rows (26x26) to T. It works fine.

I tried the same with another matrix and got:

a =

     1     4
     2     5
     3     6

>> [X,T] = a
Too many output arguments.

What's different from my a matrix to this prprog matrix?

1

There are 1 best solutions below

0
On BEST ANSWER

This simply means that your function prprob returns two matrices. In other words, it has two outputs which are the two matrices you described.

When you call [X,T] = prprob, the right hand side term (prprob) will be evaluated and thus replaced by its output. Let's call [res1,res2] this output. Then your call will be equivalent to:

[X,T] = [res1,res2]

This call holds since the two sides share the same dimension.

However, when you call [X,T] = a, your right hand side term is evaluated as a single matrix and thus the two sides of your call do not share the same dimension. This is why you get the error Too many output arguments.

Indeed, you have one input (which is a) and two outputs (which are X and T).

Note: I saw on your profile that you develop in Java. Unlike in Java where you can only have one returned variable from a method, here in Matlab, functions can return multiple variables (in an array). This is the case here for the prprob function.

Oh and as the doc says in the link you provided:

The script prprob ...

It is a function not a matrix, this might also be why you were mistaken here ;)