using a variable to change destination path in movefile

18 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by