What is [] to the left of "=" means?

2 views (last 30 days)
Superb
Superb on 9 May 2012
[processed_I] = preA(handles, connected_I, 0);
Hi, is that the [] to the left of "=" means matrix? For example, if the function return a matrix of 3X3, so the left [] will get the matrix of 3X3 too? Thanks

Answers (1)

Daniel Shub
Daniel Shub on 9 May 2012
In this case the [] does not mean anything
EDIT
[processed_I] = preA(handles, connected_I, 0);
and
processed_I = preA(handles, connected_I, 0);
mean the same thing. However
[processed_I processed_J] = preA(handles, connected_I, 0);
and
[processed_I, processed_J] = preA(handles, connected_I, 0);
are the same while
processed_I processed_J = preA(handles, connected_I, 0);
is invalid and
processed_I, processed_J = preA(handles, connected_I, 0);
mean something totally different. On the LHS of an assignment, the [] are used to denote that multiple outputs are expected such that the first output of a function is placed into processed_I and the second is placed into processed_J.
  3 Comments
Superb
Superb on 9 May 2012
Thanks Daniel, now I understand it more,
for this code,
processed_I, processed_J = preA(handles, connected_I, 0);
is it valid or not?
and for the LHS things you mean, how can we know which output will be put into processed_I, and which output will be put into processed_J?
Jan
Jan on 9 May 2012
It is trivial to check the validity of the code by your own - simply try it in Matlab.
"processed_I" will be the first output, "processed_J" the second one. The order of outputs is defined in the function header. A function defined by:
function [a, b] = fcn(c, d)
receives e.g. c as first input and replies b as second output.
These basics are explained exhaustively in the Getting Started chapters. It is recommended for all users to read them.

Sign in to comment.

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!