How do I create a cell array inside a loop?

I have a Nx1 cell array of tables called 'T' and I am looking to extarct the variables in each table but the size of 'T' can vary as can the dimensions of the tables. My code is below.
I know this can be done in a for loop using something along the lines of - for i = 1:length(data)... but how do I write the part that can create a new vars number array to hold the VariableNames in?
vars1 = T{1}.Properties.VariableNames;
vars2 = T{2}.Properties.VariableNames;
vars3 = T{3}.Properties.VariableNames;
...
...
...
varsX = T{N}.Properties.VariableNames;

댓글 수: 4

Cathal
Cathal 2023년 7월 28일
Understood!
@Cathal: just use a cell array:
F = @(t) t.Properties.VariableNames;
V = cellfun(F, T, 'uni',0)
Cathal
Cathal 2023년 7월 31일
Thanks Stephen. That will work for what I need

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Variables에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 7월 28일

댓글:

2023년 7월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by