MATLAB Answers

Creating loop to extract column from table in a cell within a cell?

5 views (last 30 days)
HC
HC on 25 Jun 2018
Answered: Gayatri Menon on 28 Jun 2018
I have F (1x99 cell), within F, there are 99 tables with different numbers of rows, but 3 columns. I want to extract the 3rd column of each cell. Finally, creating a long vector. How would I create a loop that does this?

  4 Comments

Show 1 older comment
HC
HC on 25 Jun 2018
99 Cells of F contain tables such as 100x3, 200x3, 143x3, etc. I want to extract the 3rd column of each of these then create one long final vector.

Sign in to comment.

Answers (1)

Gayatri Menon
Gayatri Menon on 28 Jun 2018
Hi,
Hope this example helps you get started. Suppose there is a cell array named cell_array which has 3 tables T1, T2 and T3 each with 3 columns - Name, Age, Weight. The following code snippet can be used to get the Weight column of all these tables and create a long vector "data":
cell_array={T1,T2,T3}
data=[];
for i=1:3
temp = cell_array{i}.Weight;
data=[data;temp]
end
Hope this helps.
Thanks
Gayatri

  0 Comments

Sign in to comment.

Sign in to answer this question.