Difference between {} and []
651 次查看(过去 30 天)
显示 更早的评论
What is the difference between
A = {0,1,2}
and
A = [0,1,2]
?
3 个评论
John D'Errico
2018-4-29
编辑:John D'Errico
2018-4-29
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
2018-4-29
编辑:dpb
2018-4-29
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.
回答(2 个)
Alfonso
2018-4-29
编辑:Alfonso
2018-4-29
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 )
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!