how can I convert matrix to cell

3 views (last 30 days)
ANKUR KUMAR
ANKUR KUMAR on 31 Oct 2017
Commented: KL on 31 Oct 2017
A=[1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
How can I convert the above matrix into
A={'1' '2' '3';'4' '5' '6';'7' '8' '9'}
=
3×3 cell array
'1' '2' '3'
'4' '5' '6'
'7' '8' '9'

Accepted Answer

KL
KL on 31 Oct 2017
Edited: KL on 31 Oct 2017
c = num2cell(A)
EDIT:
I just realized you want to convert them to char,
c = arrayfun(@num2str, A, 'uni',0)
  2 Comments
ANKUR KUMAR
ANKUR KUMAR on 31 Oct 2017
A=[2 28];
B=num2cell(A)
B =
1×2 cell array
[2] [28]
>> length(B{2})
ans =
1
I want the answer of length(B{2}) should be 2. If B is {'2','28'} then length(B{2}) is 2.
KL
KL on 31 Oct 2017
see my edited answer.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!