Creating a Cell Array in for-loop to save parts of a data from a table data format
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have a data set which is in a table data format. The dimensions of my data are 32256x25. The data basically has 576 trails per participant. Which means there are 56 participants. I want to segregate this data set and run a for-loop over it to get every participant in a separate cell array (i.e., a cell array called: participants = 1x56 and each cell should have 576x25).
Here is some code that I have tried:
k = [1:4, 11,14,15,23]; %idx of relavent cols
h = 576; % total trials per participant
tp = 1:56; %total num of participants
idx = h*tp;
% A non-loop way to index the data table and put it in a cell array
Ss_1 = ALLDATAfixed2(1:h, k);
Ss_2 = ALLDATAfixed2(idx(1)+1:idx(2), k);
Ss_3 = ALLDATAfixed2(idx(2)+1:idx(3), k);
Ss_4 = ALLDATAfixed2(idx(3)+1:idx(4), k);
participants = { ALLDATAfixed2(1:h, k), ALLDATAfixed2(idx(1)+1:idx(2), k), ALLDATAfixed2(idx(2)+1:idx(3), k),ALLDATAfixed2(idx(3)+1:idx(4), k)};
%==========================================================================================%
pp = cell(1, 56);
for kk = 1:56
for ii = 1:height(ALLDATAfixed2)
for jj = 1:length(idx)
Ss = ALLDATAfixed2([1:idx(jj), idx(jj)+1:idx(jj)], k);
tt {kk} = Ss;
end
end
end
It does not work as it gives me back a cell with 1x1 dim, and 1 cell with the whole data set back.
Help!
Thanks in advance.
0 commentaires
Réponse acceptée
Ameer Hamza
le 12 Avr 2020
You can use splitapply to partition your table without using for loops
t = array2table(rand(32256,25)); % random table replace it with your data
num_trials = 576;
num_participants = 56;
grps = repelem((1:num_participants)',num_trials,1);
split_data = splitapply(@(varargin) {[varargin{:}]}, t, grps);
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Tables 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!