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

1 回表示 (過去 30 日間)
Isabelle Museck
Isabelle Museck 2024 年 7 月 28 日
コメント済み: Umar 2024 年 7 月 29 日
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 Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by