Associative array/Iteration: Difference between revisions

m (restore alphabetical order)
(→‎{{header|MATLAB}} / {{header|Octave}}: more concise explanation)
Line 734:
=={{header|MATLAB}} / {{header|Octave}}==
 
Associative arrays arecan notbe nativedefined toas struts in Matlab and Octave, but one can (mis-)use "struct" as an associative array.
 
<lang Matlab> s.akeys = 1fieldnames(hash);
s.b = 2;
s.C = [3,4,5];
 
keys = fieldnames(s);
for k=1:length(keys),
key = keys{k};
value = getfield(shash,key); % get value of key
shash = setfield(shash,key,-value); % set value of key
disp(value);
disp(s) end; </lang>
s = setfield(s,key,-value); % set value of key
end;
disp(s) </lang>
 
or
Output:
<pre> 1
2
3 4 5
>> disp(s)
 
<lang Matlab> keys = fieldnames(shash);
scalar structure containing the fields:
for k=1:length(keys),
 
a key = -1keys{k};
value = hash.(key); % get value of key
b = -2
hash.(key) = -value; % set value of key
C =
end; </lang>
 
-3 -4 -5</pre>
 
=={{header|NetRexx}}==
Anonymous user