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

1 次查看(过去 30 天)
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 个评论
dpb
dpb 2024-7-28
编辑:dpb 2024-7-28
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 2024-7-29
@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.

请先登录,再进行评论。

回答(1 个)

Voss
Voss 2024-7-28
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

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by