【发布时间】:2022-01-15 07:07:50
【问题描述】:
使用 Matlab,我想根据名称将同一目录中存在的图像移动到两个新目录中。
目录中有两组image'名称:'neg-0.pgm', 'neg-1.pgm', 'neg-2.pgm', ... and 'pos-0.pgm' , 'pos-1.pgm', 'pos-2.pgm', ...
我尝试了不同的功能来更改图像目录,但我无法成功操作。
我的代码是:
if not(exist('./CarDataset/TrainImages/PosImages', 'dir'))
mkdir ./CarDataset/TrainImages PosImages
end
if not(exist('./CarDataset/TrainImages/NegImages', 'dir'))
mkdir ./CarDataset/TrainImages NegImages
end
trainIm = dir('./CarDataset/TrainImages/*.pgm');
for i = 1:size(trainIm, 1)
if(strcmp(trainIm(i).name, 'neg*.pgm'))
save(fullfile('./CarDataset/TrainImages/NegImages', ['neg-' num2str(i) '.pgm']))
end
end
我没有收到任何错误,但新目录仍然是空的。
【问题讨论】:
-
if contains( trainIm(i).name, 'neg' ),其他的都是else? -
有什么问题?你有错误吗?没有创建新目录?图片没有保存?您的代码的哪一部分有效,哪一部分无效?
-
@RobertoT 我没有收到任何错误,并且目录已正确创建,但图像未保存在其中。
-
从未尝试使用
save来保存实际图像,仅使用矩阵或结构。也许您应该尝试其他方式而不是该功能。可能的方式:es.mathworks.com/matlabcentral/answers/23481-how-to-save-image & stackoverflow.com/questions/22344884/…
标签: matlab directory filenames subdirectory movefile