% LIGHTWEIGHT_ENUMERATION by Shadow in 2024
% new command to improve readability of indexed for loops in code
enumerate = @(my_array) cell2mat(arrayfun(@(x,idx) struct("cargo",x,"idx",idx), my_array(:).', 1:numel(my_array(:).'),UniformOutput=false));
% SAMPLE CODE
clc
random_stuff = rand(1, 3)
column_list = (33:37).'
for outer = enumerate(column_list)
disp("Item Number " + string(outer.idx) +" contains the numer " + string(outer.cargo) + ".")
for inner = enumerate(random_stuff)
disp(" " + string(outer.idx) + ": random nr. " + string(inner.idx) + " is: " + string(inner.cargo) + ".")
end
end
引用格式
Shadow (2024). Lightweight Enumeration (https://www.mathworks.com/matlabcentral/fileexchange/168011-lightweight-enumeration), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2024a
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.0.0 |