将多个.mat文件加载到矩阵中并对其执行操作

时间:2018-12-09 08:57:50

标签: matlab matrix file-read directory-listing mat-file

我有429个大小相同的数值矩阵(107行乘36列),分别存储在依次命名的this.obj = await this.api.getStoredUser(); //if(this.obj.length < 1) - gives me error too.. i've tried everything if(this.obj !== null){ //------------ this line gives me error. this.userObj = { name: this.obj.fullname, // ------- this property gives me error. email: this.obj.email, phone: this.obj.phone, skills: this.obj.skills, unit:'', church_id: this.obj.church_id } } 文件(例如.mat)中。这是我需要做的:

  1. 导入到MATLAB工作区。
  2. 导入后,将所有像素取平均值以生成另一个矩阵,该矩阵的尺寸也为107x36。
  3. 最后,将平均矩阵的每一列与原始429个矩阵的每一列线性相关,以生成一个新的429行36列的矩阵。

到目前为止,我到了构建107 x 36 x 429阵列以填充我的矩阵集的阶段。

subj_00000.mat ... subj_00428.mat

但是我收到以下错误消息:

S = dir(fullfile(D,'subj*.mat')); % D is the path where the .mat files are saved
N = numel(S);
C = cell(1,N); % preallocate cell array
for k = 1:N
    S = load(fullfile(D,S(k).name));
    C(k) = struct2cell(S);
end
A = cat(3,C{:}); % join all of the original matrices into a 107x36x429 array
M = mean(A,3)

1 个答案:

答案 0 :(得分:0)

  

您正在遍历S却每次都覆盖它。重命名循环内的S。当您使用它时,我会为您的所有变量赋予有意义的名称-无需每次都使用单个字母。 – svdc

谢谢!我重命名了

S = load(fullfile(D,S(k).name)); 

T = load(fullfile(D,S(k).name));

成功了