Error with movefile function: argument must contain a string

2 次查看(过去 30 天)
I am trying to use the movefile(filename, directory_pathway) function to move an image file into a different folder. I am using Matlab R2014a. When I run my program I get the following error: Argument must contain a string.
Here is my code:
function dataset_randomisor()
% Set data path (the folder in which the dataset is currently stored)
data_path = 'E:\20190618-f1\images_extracted_from_zebrafish_movies\20190618-f1_10-27-56';
training_dataset_path = 'E:\20190618-f1\images_extracted_from_zebrafish_movies\training_dataset';
% Find images
images = dir(data_path);
% Randomly select 100 images
for k=1:100
img_index = randi(length(images));
random_image = images(img_index);
images(img_index) = []; % remove the selected image so that it doesn't get selected twice
movefile({random_image.name},training_dataset_path);% move the selected image to the training dataset
end
end
Does anyone know what I'm doing wrong, and/or how I can fix it?

采纳的回答

Walter Roberson
Walter Roberson 2019-9-6
{random_image.name} is a cell array with a character vector inside it. That name does not include the directory either
fullfile(data_path, random_directory.name)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2014a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by