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 Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by