using a variable to change destination path in movefile

24 vues (au cours des 30 derniers jours)
alastair crotty
alastair crotty le 22 Avr 2021
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

Réponse acceptée

DGM
DGM le 22 Avr 2021
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);

Plus de réponses (1)

Monika Jaskolka
Monika Jaskolka le 22 Avr 2021
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);

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by