Difference between {} and []

658 views (last 30 days)
alpedhuez
alpedhuez on 29 Apr 2018
Answered: Image Analyst on 30 Apr 2018
What is the difference between
A = {0,1,2}
and
A = [0,1,2]
?
  3 Comments
John D'Errico
John D'Errico on 29 Apr 2018
Edited: John D'Errico on 29 Apr 2018
help parens
does give a nice explanation. I was actually surprised that
doc parens
finds nothing at all. A further check shows that I had to do
doc paren
in order for it to give me help. That seems a bit silly, because when I did help on parens, it told me that it could not find parens, so it gave me the help for paren. Why was doc not as smart as help? (Probable answer: because they were written by different people, to subtly different specs.)
dpb
dpb on 29 Apr 2018
Edited: dpb on 29 Apr 2018
What's more is that
help paren
help parens
both return the same help page.
I'm of the age and began using Matlab when all you had from the opening command line was 'help' and I still recommend for all newcomers that is really still a very good exercise to go through of just skimming the various categories; that overview is invaluable to get a feeling for what facilities are available in what areas very quickly; far more than trying to dig through the doc.
One does have to use
>> help
HELP topics:
Documents\MATLAB - (No table of contents file)
matlab\datafun - Data analysis and Fourier transforms.
matlab\datatypes - Data types and structures.
matlab\elfun - Elementary math functions.
matlab\elmat - Elementary matrices and matrix manipulation.
matlab\funfun - Function functions and ODE solvers.
matlab\general - General purpose commands.
matlab\iofun - File input and output.
matlab\lang - Programming language constructs.
matlab\matfun - Matrix functions - numerical linear algebra.
matlab\ops - Operators and special characters.
matlab\polyfun - Interpolation and polynomials.
matlab\randfun - Random matrices and random streams.
matlab\sparfun - Sparse matrices.
matlab\specfun - Specialized math functions.
matlab\strfun - Character arrays and strings.
matlab\timefun - Time and dates.
...
>> help ops
to get to paren under the 'Special Characters' section.
But, if in parallel to
>> help
one tries
>> doc
you get the welcome page and no way afaict to get an equivalent list of links to the content as organized in help files; while the
>> doc paren
opens the help files in the html view but from
>> doc
all searches are restricted to within the doc files; the help files aren't indexed so there's no getting across the great divide from that direction while from the Help view there's a link Topics that opens the main doc window; once there there's backtrack; you have to close that window and return to the one left to get back to the help file viewer.

Sign in to comment.

Answers (2)

Alfonso
Alfonso on 29 Apr 2018
Edited: Alfonso on 29 Apr 2018
A = {0,1,2} constructs an array of class cell, basically this type of class can contain any type of data. For further information ( https://es.mathworks.com/help/matlab/cell-arrays.html )
A = [0,1,2] uses the matrix constructor operator, which in your case will construct you a three element-vector of class double or a one row matrix of three elements of class double, which is the same. For further information you can take a look here ( https://es.mathworks.com/help/matlab/math/creating-and-concatenating-matrices.html )

Image Analyst
Image Analyst on 30 Apr 2018

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!