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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Voss
am 14 Mai 2022
Try changing this:
tf_all(subno,:,:,:,:) = tf(subno);
to this:
tf_all(subno,:,:,:,:) = tf;
2 Kommentare
Voss
am 15 Mai 2022
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!
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu EEG/MEG/ECoG finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!