using a variable to change destination path in movefile

19 Ansichten (letzte 30 Tage)
alastair crotty
alastair crotty am 22 Apr. 2021
Beantwortet: Monika Jaskolka am 22 Apr. 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

Akzeptierte Antwort

DGM
DGM am 22 Apr. 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);

Weitere Antworten (1)

Monika Jaskolka
Monika Jaskolka am 22 Apr. 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);

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by