using a variable to change destination path in movefile

조회 수: 19 (최근 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 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