Creating table with array in element

조회 수: 3 (최근 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 CenterFile Exchange에서 LaTeX에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by