How can I convert strings inside tables back to character arrays using convertCon​tainedStri​ngsToChars in MATLAB R2025b?

I am working in MATLAB R2025b and using modern features like string arrays and tables. However, I need to maintain compatibility with a legacy codebase that requires outputs as char arrays or cell arrays of characters.
I normally use the "convertContainedStringsToChars" function before passing data back to the legacy code. This works for cells and structs, but when I try to use it on a table that contains string variables, the function does not convert the strings back to char arrays.
Reproduction steps:
>> expected_output = table({'one'; 'two'})
>> string_table = table(["one"; "two"])
>> char_table = convertContainedStringsToChars(string_table)
The output:
What is the cause of this issue?
Is there a way to make "convertContainedStringsToChars" handle tables recursively, or is there a recommended workaround to achieve this conversion?

 Accepted Answer

Cause of the Issue
As of MATLAB R2025b, "convertContainedStringsToChars" does not recursively process tables. It only converts strings inside cells or struct fields and leaves tables unchanged. This is documented behaviour.
Workaround
Use the "convertvars" function to convert table variables between supported types. For example, to convert string variables in a table to cell arrays of character vectors:
>> expected_output = table({'one'; 'two'})
>> string_table = table(["one"; "two"])
>> char_table = convertvars(string_table, vartype("string"), 'cellstr')
For additional information, please refer to the documentation page on the "covertvars" function.

More Answers (0)

Categories

Products

Release

R2025b

Community Treasure Hunt

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

Start Hunting!