# 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 vue (au cours des 30 derniers jours)
Joanne Hall le 14 Mai 2022
Commenté : Voss le 15 Mai 2022
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.
Below is code.
***********************************
clear, close all
% Get a list of data files ready to be analyzed
sublist = dir('*tf*.mat');
sublist = {sublist.name};
for subno=1:length(sublist)
% 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 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Voss le 14 Mai 2022
Try changing this:
tf_all(subno,:,:,:,:) = tf(subno);
to this:
tf_all(subno,:,:,:,:) = tf;
##### 2 commentairesAfficher AucuneMasquer Aucune
Joanne Hall le 14 Mai 2022
Omg it worked!! Thank you, you are awesome!!
Voss le 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)
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!

Connectez-vous pour commenter.

### Catégories

En savoir plus sur EEG/MEG/ECoG dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by