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

1 Ansicht (letzte 30 Tage)
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 Kommentare
dpb
dpb am 28 Jul. 2024
Bearbeitet: dpb am 28 Jul. 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 am 29 Jul. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

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

Kategorien

Mehr zu Tables 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!

Translated by