用于加载和保存.mat文件的循环

时间:2012-05-15 12:20:28

标签: matlab file-io mat-file

我有一个带.mat文件的文件夹,我想编写一个循环来加载这些文件并对数据执行一些操作:

1)选择我的数据文件夹

2)执行以下操作集(伪代码):

for i = 1:99
    load 'Data0i.mat' ('Datai.mat', if i > 9);
    data = data * 10;
    save data as 'Data0i.mat' to another folder;
end;

MATLAB的实现是什么?

1 个答案:

答案 0 :(得分:1)

inputFolder = 'infolder';
outputFolder = 'outfolder';

for i = 1:99
    %# Load data
    inputFilename = sprintf('%s/%02d.mat', inputFolder, i);
    load(inputFilename)

    %# Process data
    data = data * 10;

    %# Savedata
    outputFilename = sprintf('%s/%02d.mat', outputFolder, i);
    save(outputFilename, 'data')
end