Creating loop to extract column from table in a cell within a cell?
이전 댓글 표시
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
Image Analyst
2018년 6월 25일
By "cell within a cell" do you mean that each of the 99 cells of F has another cell array inside them and that cell array is a 97-by-3 cell array? And you want to extract a new cell array which is column 3 of the cell arrays, so in the end you will have a 99-by-1 cell array where each cell contains a 97-by-1 cell array?
I think your terminology might be getting confused. Please see the FAQ and clarify your wording: https://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
Note that there is a difference between a cell and a cell array. A cell array is composed of a bunch of cells, each cell can contain anything such as another cell, another cell array, a double array, a scalar, a structure or structure array, or whatever you want.
HC
2018년 6월 25일
답변 (1개)
Gayatri Menon
2018년 6월 28일
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
댓글 수: 1
Hello! It is really helpful for a cell array with 1x4 dimension. But for my case, I have a cell array of 1x24 that has 24 tables in it. I want to create a long vector for Weight column of each 4 tables using loops. At the end, I want to get six long vector for Weight column. Thanks!
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!