我想用scilab阅读一些图像,我使用像这样的函数imread
im01=imread('kodim01t.jpg');
im02=imread('kodim02t.jpg');
im03=imread('kodim03t.jpg');
im04=imread('kodim04t.jpg');
im05=imread('kodim05t.jpg');
im06=imread('kodim06t.jpg');
im07=imread('kodim07t.jpg');
im08=imread('kodim08t.jpg');
im09=imread('kodim09t.jpg');
im10=imread('kodim10t.jpg');
我想知道是否有办法做以下的事情来优化
for i = 1:5
im&i=imread('kodim0&i.jpg');
end
提前致谢
答案 0 :(得分:1)
我使用execstr或使用某种列表/矩阵
看到了两种可能的解决方案首先使用msprintf创建要执行的命令字符串,然后使用execstr执行此操作。请注意,在msprintf转换中,%0d
格式说明符descbribed here会插入正确数量的前导零。
for i = 1:5
cmd=msprintf('im%d=imread(\'kodim%02d.jpg\');', i, i);
execstr(cmd);
end
这可能是使用可编制容器(例如list。
)的更直观的选项// This list could be generated using msprintf from example above
file_names_list = list("kodim01t.jpg", "kodim02t.jpg" ,"kodim03t.jpg");
// Create empty list to contain images
opened_images = list();
for i=1:length(file_names_list)
// Open image and insert it at end of list
opened_images($+1) = imread(file_names_list[i]);
end