1

I have a: 1×7 cell array of strings:

arr1 = '0.1' '0.4' '0.0' '0.1' '0.4' '0.0' '2.1'

I need to transform this thing into a proper matrix 1x7 matrix. If I do:

cell2mat(arr1)

I get:

'0.10.40.00.10.40.02.1'

It gives me a single string. What am I doing wrong?

1 Answer 1

2

Use str2double:

>> arr1 = {'0.1' '0.4' '0.0' '0.1' '0.4' '0.0' '2.1'};
>> result = str2double(arr1)
result =
    0.1000    0.4000         0    0.1000    0.4000         0    2.1000

Why didn't your approach work? Because cell2mat simply concatenates the contents of the cells, which are strings, so you get a single string instead of several numbers.

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

1 Comment

@Andry Prego! :-)

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.