Creating table with array in element

4 ビュー (過去 30 日間)
Philip Shaw
Philip Shaw 2021 年 6 月 2 日
コメント済み: Walter Roberson 2021 年 6 月 2 日
I am trying to create a table which includes an array in each row (like the output from regionprops etc.)
I know how to do it by creating a struct and using struct2table, but is there are way to create a blank table with an array variable using the table('Size', [..], 'VariableTypes', ...) constructor?
I have tried searching but any useful results are buried under posts about array2table.

採用された回答

Walter Roberson
Walter Roberson 2021 年 6 月 2 日
You do not need to do anything special. Once the variable exists, you can write over the content with an array
t = table('Size', [3 2], 'VariableTypes', {'uint8', 'double'})
t = 3×2 table
Var1 Var2 ____ ____ 0 0 0 0 0 0
t.Var2 = zeros(3, 2)
t = 3×2 table
Var1 Var2 ____ ______ 0 0 0 0 0 0 0 0 0
The only challenge would be to have a variable created in the table to have an initial size that has multiple columns; there is no provision for doing that as one step (other than calling table() and passing in content of the appropriate size.)
  2 件のコメント
Philip Shaw
Philip Shaw 2021 年 6 月 2 日
I see, I was trying to assign the individual elements and so getting a size mismatch.
I suppose that means there's no way to put a multi-row matrix in a table element, apart from wrapping it in a cell or reshaping it so the first dimension has length 1.
Walter Roberson
Walter Roberson 2021 年 6 月 2 日
You can see that regionpops does it by using cell() for the multi-row entries.
img = imread('cameraman.tif');
bw = img > 224;
imshow(bw)
props = regionprops('table', bw, 'area', 'centroid', 'extrema')
props = 31×3 table
Area Centroid Extrema ____ ________________ ____________ 28 106.61 173.61 {8×2 double} 1 103 76 {8×2 double} 69 105.81 242.49 {8×2 double} 5 108 230 {8×2 double} 1 111 215 {8×2 double} 6 112.83 206.33 {8×2 double} 3 112 210 {8×2 double} 1 116 190 {8×2 double} 1 119 175 {8×2 double} 3 130 89 {8×2 double} 89 140.51 95.562 {8×2 double} 46 135.2 143.52 {8×2 double} 2 135.5 165 {8×2 double} 1 135 180 {8×2 double} 18 135 190.5 {8×2 double} 2 137 114.5 {8×2 double}
varfun(@class, props)
ans = 1×3 table
class_Area class_Centroid class_Extrema __________ ______________ _____________ double double cell

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLaTeX についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by