0

Hi I have a cell array which I want to convert to a matrix:

a = {'1.2'; '1.3'; '1.45'}
cell2mat(a)

Gives me the error:

Error using cat
CAT arguments dimensions are not consistent.

Error in cell2mat (line 84)
            m{n} = cat(1,c{:,n});

Please help thank you!

1
  • 3
    You have a cell array of chars. Use str2double: >> str2double(a) Commented Dec 7, 2018 at 10:26

2 Answers 2

4

cell2mat fails because it's expecting numeric elements in the cell array, to be placed in a matrix. You have character arrays, not numeric elements, so you need to use str2double to convert them to doubles (the output is a matrix as desired).

a = {'1.2'; '1.3'; '1.45'};
out = str2double( a ); 
Sign up to request clarification or add additional context in comments.

Comments

-1

You may try the below one:

a = {[1.2]; [1.3]; [1.45]}
cell2mat(a)

1 Comment

This doesn't take the same inputs as stated in the OP (i.e. you're inputting a cell of doubles, the OP has a cell of chars), so this doesn't answer the question.

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.