Error using movefile: Arguments must contain a character vector.

조회 수: 4 (최근 30일)
Yash Patel
Yash Patel 2019년 2월 3일
댓글: Yash Patel 2019년 2월 3일
I have a whole bunch of images that I need to sort and save based on their study, name and date, which is there in the name of the images itself, eg "ABC_20180712_121343_L_001.png", where the 2nd portion is the date, 3rd being the time stamp, 4th being the criteria of the study and 5th is the image number. So, I create a new folder reading the name, criteria and date, eg "L_20180712_121343", but time only in cases where there are two images of the same date. After that I try to move the image to that folder, but matlab shows the error "Error using movefile: Arguments must contain a character vector." Here is part of whole code:
for k=3:length(dir_L)
name_img = dir_L(k,1).name; %read the names
name_1 = strsplit(name_img,{'_','.'});
name = name_1{1};
date = name_1{2};
time = name_1{3};
study = name_1{4};
if k==3
newfolder=strcat(study,'_',date); %naming the new folder
mkdir(newfolder); %creating the folder
end
img = imread(name_img);
movefile (img, newfolder); %transfering the images to the folder
end
I don't know what am I doing wrong.

채택된 답변

Stephen23
Stephen23 2019년 2월 3일
편집: Stephen23 2019년 2월 3일
Read the movefile help: does it say that its first input should be some image data? (hint: no). Does it say that its first input should be a filename or foldername? (hint: yes). That error message tells you what is wrong (which is why you should pay attention to what error messages actually say).
Get rid of the imread, and then use movefile according to its documentation:
movefile(name_img, newfolder)
  댓글 수: 1
Yash Patel
Yash Patel 2019년 2월 3일
Thank you for the answer, and I will pay more attention to what error messages actually say from now on.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by