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?
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?
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.
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":
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
4 Comments
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/407327-creating-loop-to-extract-column-from-table-in-a-cell-within-a-cell#comment_582367
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/407327-creating-loop-to-extract-column-from-table-in-a-cell-within-a-cell#comment_582367
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/407327-creating-loop-to-extract-column-from-table-in-a-cell-within-a-cell#comment_582374
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/407327-creating-loop-to-extract-column-from-table-in-a-cell-within-a-cell#comment_582374
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/407327-creating-loop-to-extract-column-from-table-in-a-cell-within-a-cell#comment_582379
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/407327-creating-loop-to-extract-column-from-table-in-a-cell-within-a-cell#comment_582379
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/407327-creating-loop-to-extract-column-from-table-in-a-cell-within-a-cell#comment_582381
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/407327-creating-loop-to-extract-column-from-table-in-a-cell-within-a-cell#comment_582381
Sign in to comment.