convertContainedStringsToChars

Converts strings found inside cell arrays to character vectors.

Category: Language Fundamentals > Data Types

Syntax

B = convertContainedStringsToChars(A)

Returns A with every string, at any depth of cell nesting, replaced by a char vector.

Description

This is the recursive form of convertStringsToChars: where that function looks at the top level, this one also converts strings inside nested cell arrays. It is useful for cleaning inputs before passing them to code that expects char vectors.

Input arguments

A
A value, usually a cell array that may hold strings.

Output arguments

B
Value with the same structure as A but no strings.

Example

Strings in a cell array

B = convertContainedStringsToChars({"a", "bc", 3});
class(B{1})
class(B{3})
B
Output
ans = 'char'
ans = 'double'
B = 1×3 cell

    {'a'}    {'bc'}    {[3]}

Notes

MatLivre converts only the strings at the top level of the cell array; strings inside nested cell arrays or structs are left unchanged.

See also

convertStringsToChars convertCharsToStrings cellstr char