0

I have MATLAB set to record three webcams at the same time. I want to capture and save each feed to a file and automatically increment it the file name, it will be replaced by experiment_0001.avi, followed by experiment_0002.avi, etc.

My code looks like this at the moment

set(vid1,'LoggingMode','disk');
set(vid2,'LoggingMode','disk');

avi1 = VideoWriter('X:\ABC\Data Collection\Presentations\Correct\ExperimentA_002.AVI');
avi2 = VideoWriter('X:\ABC\Data Collection\Presentations\Correct\ExperimentB_002.AVI');
set(vid1,'DiskLogger',avi1);
set(vid2,'DiskLogger',avi2);

and I am incrementing the 002 each time.

Any thoughts on how to implement this efficiently?

Thanks.

1 Answers1

0

dont forget matlab has some roots to C programming language. That means things like sprintf will work

so since you are printing out an integer value zero padded to 3 spaces you would need something like this sprintf('%03d',n) then % means there is a value to print that isn't text. 0 means zero pad on the left, 3 means pad to 3 digits, d means the number itself is an integer

just use sprintf in place of a string. the s means String print formatted. so it will output a string. here is an idea of what you might do

set(vid1,'LoggingMode','disk');
set(vid2,'LoggingMode','disk');

for (n=1:2:max_num_captures)
    avi1 = VideoWriter(sprintf('X:\ABC\Data Collection\Presentations\Correct\ExperimentA_%03d.AVI',n));
    avi2 = VideoWriter(sprintf('X:\ABC\Data Collection\Presentations\Correct\ExperimentB_002.AVI',n));
    set(vid1,'DiskLogger',avi1);
    set(vid2,'DiskLogger',avi2);
end
andrew
  • 2,451
  • 1
  • 15
  • 22