How to pull out data from cell array, concatenate it, and put into table for varying trials

1 visualización (últimos 30 días)
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 comentarios
dpb
dpb el 28 de Jul. de 2024
Editada: dpb el 28 de Jul. de 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
Umar el 29 de Jul. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Voss
Voss el 28 de Jul. de 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

Categorías

Más información sobre Tables en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by