creating uber matrix composed of smaller EEG data matrices (in a for loop): undesired outcome: creates 1 number that repeats in every cell for each subject

1 回表示 (過去 30 日間)
Dear matlab,
Goal: to create an uber mother matrix of EEG channel data sets, into one matrix.
My EEG data for each individual subject is saved with the variable name " tf " (which time-frequency decomposition result), and is a 4-D double matrix: channels X frequencies X time points X trials.
The below for loop should load files into one uber mother matrix, which results in a 5-D matrix:
subjects X channels X frequencies X time points X trials
The uber matrix is created in 5-D, but there is a problem: The problem is that, in the end, there is only one number that repeats in every cell of the matrix, for each participant.
For the 1st subject, matlab takes the 1st cell and repeats the same number in all cells, for the rest of the matrix, for that subject.
For the 2nd sbject, matlab takes the single value from the 2nd row, 1st column, and repeats THAT number across the remaining cells, for that subject.
so in the end, my entire uber matrix is filled with only 2 numbers. Please help. Thank you in advance.
Below is code.
***********************************
clear, close all
% Get a list of data files ready to be analyzed
sublist = dir('*tf*.mat');
sublist = {sublist.name};
%% load in level-1 data
for subno=1:length(sublist)
load(sublist{subno})
% initialize matrices on 1st subject
if subno==1
tf_all = zeros([ length(sublist) size(tf) ]);
end
% place single-subject data into group-size matrices
tf_all(subno,:,:,:,:) = tf(subno);
end % end loop around subjects

採用された回答

Voss
Voss 2022 年 5 月 14 日
Try changing this:
tf_all(subno,:,:,:,:) = tf(subno);
to this:
tf_all(subno,:,:,:,:) = tf;
  2 件のコメント
Joanne Hall
Joanne Hall 2022 年 5 月 14 日
Omg it worked!! Thank you, you are awesome!!
Voss
Voss 2022 年 5 月 15 日
You're welcome!
The problem was that tf(subno), which is one element of tf (specifically, element # subno), was being assigned to all elements of tf_all(subno,:,:,:,:).
Consider a similar situation with smaller matrices:
M = [1 2; 3 4];
M_all = zeros(2,2,2);
The way it was, was like saying this:
M_all(1,:,:) = M(1)
M_all =
M_all(:,:,1) = 1 1 0 0 M_all(:,:,2) = 1 1 0 0
when you meant to say this:
M_all(1,:,:) = M
M_all =
M_all(:,:,1) = 1 3 0 0 M_all(:,:,2) = 2 4 0 0
Anyway, let me know if you have any other questions about it. Otherwise, if that solves the problem, please click "Accept This Answer". I appreciate it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEEG/MEG/ECoG についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by