How to pull out data from cell array, concatenate it, and put into table for varying trials
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello there, I have data from 10 trials stored in a 1x10 cell array "Predictors" and I want to create a loop that pulls out one trial at a time and then concatonates the data in all the other trials and saves it under a unique or numbered variable name? I am thinking something like this. I am not sure how to have it number each iteration:
for i = 1:length(Predictors)
Test_i = Predictors(i)
trainindicies_i = setdiff(1:length(Predictors),i);
Train_i = Predictors(trainindicies)
TrainX_i = vertcat(Train_i{:})
end
8 commentaires
dpb
le 28 Juil 2024
Modifié(e) : dpb
le 28 Juil 2024
Huh. I asked for that enhancement ages ago but owing to that summary had never actually tried it and missed seeing it in a new features blurb (which, I admit, I generally don't bother to read which puts the blame directly onto me, granted!)
Thanks for pointing it out, I'll have to begin using them...I've always hated to have to use the clumsy (size,1).
I see they still haven't gone along with the idea for The Third Dimension, though... :(
Umar
le 29 Juil 2024
@dpb & @Walter, @Stephen23, sounds like Voss joined the party as well, and shared the code snippet that you guys were talking about. I want to thank everyone of you sharing your thoughts and glad to know that we are working as a team to help out each other.
Réponses (1)
Voss
le 28 Juil 2024
T = table();
N = numel(Predictors);
for ii = 1:N
idx = [1:ii-1 ii+1:N];
T.(sprintf('Train_%d',ii)) = vertcat(Predictors{idx});
end
1 commentaire
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!