what is the difference between n={ } and n=[], and what are they?

 Accepted Answer

{} is used for cells and [] for arrays (matrix) both can store strings but the arrays can't store strings and numeric values at the same time.
Square Brackets — [ ]
Square brackets are used in array construction and concatenation, and also in declaring and capturing values returned by a function
Curly Braces — { }
Use curly braces to construct or get the contents of cell arrays.

6 Comments

Look for more at Symbol Reference in your matlab documentation.
so if I want to store both date_string and number in a single matrix, I should use the curly braces-{}.
what is the command to copy the content from arrays[] to cells{}?
should i use loop:
for i=1:10
for j=1:10
a{i,j}=b(i,j);
end
end
a = num2mat(b) will do the same thing as your loop.
a is an array matrix <1241x11 double>
But,
>> z = num2mat(a)
??? Undefined function or method 'num2mat' for input arguments of
type 'double'.
>> clear z
>> z = num2mat(a)
??? Undefined function or method 'num2mat' for input arguments of
type 'double'.
Sorry, that should have been num2cell

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!