2

I want to convert a structure to a cell array where all the entries are converted to strings, including numbers. If I take the MATLAB example:

s = 
    category: 'tree'
      height: 37.4000
        name: 'birch'

I want to convert this to

c = 
    'tree'
    '37.4000'
    'birch'

where all entries are converted to strings, including numbers. The function struct2cell(s) will convert s to:

ans =
    'tree'
    [37.4000]
    'birch'

Is there a quick way of getting from s to c?

1 Answer 1

3

If you want to force everything to a string, you can use num2str with cellfun:

cellfun(@num2str, struct2cell(a), 'UniformOutput', false)

The result will be a cell array of strings.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.