Associative array/Iteration: Difference between revisions
Content added Content deleted
m (restore alphabetical order) |
(→{{header|MATLAB}} / {{header|Octave}}: more concise explanation) |
||
Line 734: | Line 734: | ||
=={{header|MATLAB}} / {{header|Octave}}== |
=={{header|MATLAB}} / {{header|Octave}}== |
||
Associative arrays |
Associative arrays can be defined as struts in Matlab and Octave. |
||
<lang Matlab> |
<lang Matlab> keys = fieldnames(hash); |
||
s.b = 2; |
|||
s.C = [3,4,5]; |
|||
⚫ | |||
for k=1:length(keys), |
for k=1:length(keys), |
||
key = keys{k}; |
key = keys{k}; |
||
value = getfield( |
value = getfield(hash,key); % get value of key |
||
⚫ | |||
disp(value); |
|||
⚫ | |||
⚫ | |||
end; |
|||
⚫ | |||
or |
|||
Output: |
|||
<pre> 1 |
|||
2 |
|||
3 4 5 |
|||
>> disp(s) |
|||
⚫ | |||
scalar structure containing the fields: |
|||
for k=1:length(keys), |
|||
key = keys{k}; |
|||
value = hash.(key); % get value of key |
|||
b = -2 |
|||
hash.(key) = -value; % set value of key |
|||
C = |
|||
⚫ | |||
-3 -4 -5</pre> |
|||
=={{header|NetRexx}}== |
=={{header|NetRexx}}== |