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
0 个评论
采纳的回答
Voss
2022-5-14
Try changing this:
tf_all(subno,:,:,:,:) = tf(subno);
to this:
tf_all(subno,:,:,:,:) = tf;
2 个评论
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)
when you meant to say this:
M_all(1,:,:) = M
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 Exchange 中查找有关 EEG/MEG/ECoG 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!