1

I'm trying to write a function that accepts a cell array of strings and builds a vector of numbers of the same length. Each item in the output vector will be the length of the strings in each cell array. If someone could please help me or show me a written example of this I would appreciate it very much. I'm new to matlab and have been working on getting this to work for a long time and cant on my own. Thank You.

2 Answers 2

2

A slightly more succinct version of zellus's answer:

s = {'one', 'two', 'three'};
numbers = cellfun(@length, s)
Sign up to request clarification or add additional context in comments.

Comments

1

Cellfun is one option to retrieve the string lengths as shown in the following example:

s = cellstr(strvcat('one','two','three'))
numbers = cellfun(@(x) length(char(x)), s)

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.