Associative array/Creation: Difference between revisions

Content added Content deleted
(MATLAB/Octave: Split into subcategories, added containers.Map example)
m (MATLAB/Octave: fixed capitalization of language tags)
Line 1,316: Line 1,316:
Associative arrays are called structs. The following methods of creating hash are equivalent.
Associative arrays are called structs. The following methods of creating hash are equivalent.


<lang Matlab> hash.a = 1;
<lang MATLAB> hash.a = 1;
hash.b = 2;
hash.b = 2;
hash.C = [3,4,5]; </lang>
hash.C = [3,4,5]; </lang>
alternatively
alternatively
<lang Matlab> hash = [];
<lang MATLAB> hash = [];
hash = setfield(hash,'a',1);
hash = setfield(hash,'a',1);
hash = setfield(hash,'b',2);
hash = setfield(hash,'b',2);
hash = setfield(hash,'C',[3,4,5]); </lang>
hash = setfield(hash,'C',[3,4,5]); </lang>
or
or
<lang Matlab> hash.('a') = 1;
<lang MATLAB> hash.('a') = 1;
hash.('b') = 2;
hash.('b') = 2;
hash.('C') = [3,4,5]; </lang>
hash.('C') = [3,4,5]; </lang>