matlab iterative filenames for saving

前端 未结 4 1417
情书的邮戳
情书的邮戳 2020-12-21 08:24

this question about matlab: i\'m running a loop and each iteration a new set of data is produced, and I want it to be saved in a new file each time. I also overwrite old fi

4条回答
  •  甜味超标
    2020-12-21 08:43

    You could also generate all file names in advance using NUM2STR:

    >> filenames = cellstr(num2str((1:10)','string_new.%02d.mat'))
    
    filenames = 
        'string_new.01.mat'
        'string_new.02.mat'
        'string_new.03.mat'
        'string_new.04.mat'
        'string_new.05.mat'
        'string_new.06.mat'
        'string_new.07.mat'
        'string_new.08.mat'
        'string_new.09.mat'
        'string_new.10.mat'
    

    Now access the cell array contents as filenames{i} in each iteration

提交回复
热议问题