using a variable to change destination path in movefile

18 ビュー (過去 30 日間)
alastair crotty
alastair crotty 2021 年 4 月 22 日
回答済み: Monika Jaskolka 2021 年 4 月 22 日
I need to change the destination path each time a picture is taken, so that it can move the picture from one file to a new file (so it doesnt overwrite the last image taken). After taking the picture I've got the variable 'dest_path' so that it changes the string for the image number each time, but movefile comes up with an error for 'invalid use of operator', can anyone help with this?
for n=1:10
my_buggy.camera();
dest_path=sprintf('C:/Users/alast/Desktop/buggy_simulator/floor/%d.jpg',n);
movefile(C:/users/alast/Documents/LAB 5/images, dest_path);
end

採用された回答

DGM
DGM 2021 年 4 月 22 日
The first argument here needs to be a string, so put it in quotes (and pay attn to case)
movefile('C:/Users/alast/Documents/LAB 5/images', dest_path);
And to avoid future headaches, zero-pad the file numbers:
dest_path=sprintf('C:/Users/alast/Desktop/buggy_simulator/floor/%04d.jpg',n);

その他の回答 (1 件)

Monika Jaskolka
Monika Jaskolka 2021 年 4 月 22 日
Your first problem is that the first input into movefile should be a char array:
movefile('C:/users/alast/Documents/LAB 5/images', dest_path);
Second, this first input is a folder, so you need to change it to be the actual file you are moving:
movefile('C:/users/alast/Documents/LAB 5/images/filename.jpg', dest_path);

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by