Matlab:Movefile函数无法正确排序图像

时间:2020-08-03 23:57:52

标签: excel matlab file

我正在尝试在Matlab 2019b中使用movefile函数,但出现以下错误:

Error using movefile
Unknown error occurred.

Error in image_sort (line 19)
  movefile(source,destination);

我的代码如下。

imagefiles = dir('HAM10000_images_combined\');      
nfiles = length(imagefiles);  
% Open directory with images and count the number of files
for k = 1 : nfiles
  %For every file
  currentfilename = imagefiles(k).name;
  %Get filename
  
  xlrangeLeft = sprintf('C%s', num2str(k+1));
  xlrangeRight = sprintf(':C%s', num2str(k+1));
  xlRange = strcat(xlrangeLeft, xlrangeRight); 
  %Get cell range that has the class data for that specific image
  [~, class] = xlsread('HAM10000_metadata_sorted.xlsx','HAM10000_metadata_sorted', xlRange);
  class = char(class); 
  %Retrieve class data. 
  source = strcat('HAM10000_images_combined\', currentfilename);
  destination = strcat('HAM10000_images_sorted\', class, '\');
  movefile(source,destination);
  % Move file to its corresponding class
end

HAM10000metadata_sorted.xlsx是一个Excel文件,该文件在每个图像的列中包含类数据。像这样:

"nv"
"nv"
"mel"
"nv"
etc.

合并的文件夹包含所有图像,而排序的文件夹中包含每个类别的文件夹。目的是将图像从合并的文件夹移动到已排序文件夹中的正确文件夹。

应该从excel表中读取代码以获取有关图像的类详细信息。然后应该将图像从合并的文件夹移动到已排序的文件夹,并将其正确放置在正确的classes文件夹中。但是,它最终删除了合并的文件夹并创建了一个新的Ham10000_images_sorted文件夹,即使该文件夹已经存在。在这个新生成的文件夹中,所有图像最终都位于“ nv”文件夹中,而其他所有类都没有文件夹。

您是否对为什么代码无法对图像进行排序有任何见解?

0 个答案:

没有答案