Clear Filters
Clear Filters

what is the difference between A=[]; and A={}; ?

7 views (last 30 days)
Kanwal Kaur
Kanwal Kaur on 18 Nov 2016
Commented: dbmn on 18 Nov 2016
what is the difference between A=[]; and A={}; ?

Accepted Answer

dbmn
dbmn on 18 Nov 2016
One initializes the variable as a double (or array of doubles) and the other as a cell (or a cell array)
>> A=[];
>> class(A)
ans =
double
and
>> B={};
>> class(B)
ans =
cell
  2 Comments
Kanwal Kaur
Kanwal Kaur on 18 Nov 2016
means A=[] can store only double values??
dbmn
dbmn on 18 Nov 2016
no. You can still do things like:
>> A=[];
>> A{2}='asdf';
>> class(A)
ans =
cell
without encountering an error

Sign in to comment.

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!