What is [] to the left of "=" means?
2 views (last 30 days)
Show older comments
[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
0 Comments
Answers (1)
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
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.
See Also
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!