Question Details

No question body available.

Tags

arrays string matlab struct char

Answers (2)

February 6, 2026 Score: 1 Rep: 30,777 Quality: Low Completeness: 70%

Can you just do tbl = struct2table( A, 'AsArray', true); and then if you particularly need one data type or the other you can use

  • tbl.Name = cellstr( tbl.Name ); for a cell array of chars (a cellstr)
  • tbl.Name = string( tbl.Name ); for a string array

to ensure you have a known data type in the table.

Table columns are then a little easier to work with than struct arrays without assigning to individual variables Names and Values.

February 6, 2026 Score: 0 Rep: 113,417 Quality: Low Completeness: 70%

A not very well known feature of char is that it can do that, right-padding each row of chars with spaces as necessary. Its inputs can be a cell array or a comma-separated list. So, given

A(1).Name = 'abc'; A(2).Name = 'defg';

you can use either

>> char({A.Name}) ans = 2×4 char array 'abc ' 'defg'

or more simply

>> char(A.Name) ans = 2×4 char array 'abc ' 'defg'

If you want to avoid padding, you can generate a cell array of char vectors:

>> {A.Name}.' ans = 2×1 cell array {'abc' } {'defg'}