Search code examples
matlabmatlab-figureavi

matlab: how to concatenate strings?


I want to produce multiple movies in matlab like

for i=1:5
   %calculate a movie-array H (gridsize depends on i)
   number=num2str(i);
   movie2avi(H, 'movie_'+number+'.avi');
end

Obviously it doesn't work and I found nothing about multiple movie production in matlab. Any idea how to vary the filename in this command to produce different movie-files instead of overwrite one file?


Solution

  • In matlab you concatenate strings using strcat and not using + operator!

    Try

    movie2avi( H, strcat('movie_', number, '.avi') );
    

    Alternatively, you can use [] to concat the literals into a string

    movie2avi( H, ['movie_', number, '.avi'] );