Lightweight Enumeration

版本 1.0.0 (1.4 KB) 作者: Shadow
Enumeration, i.e ForEach + Index. A small anonymous one liner, that allows for better readability of indices.
0.0 次下载
更新 2024/6/13

查看许可证

% 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 (2026). Lightweight Enumeration (https://ww2.mathworks.cn/matlabcentral/fileexchange/168011-lightweight-enumeration), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2024a
兼容任何版本
平台兼容性
Windows macOS Linux
标签 添加标签
版本 已发布 发行说明
1.0.0