# how to convert cell to matrix ?

2 views (last 30 days)
pruth on 1 Nov 2019
Commented: pruth on 1 Nov 2019
i have this cell x (20*1) (i have attached). i just want convert this in to simple matrix and split the data whereever there is a space.
so here i will get the 20*20 matrix !
i tried splitting the each string with single space in a loop but it seems like sometimes there are two spaces, sometimes 3 and sometimes only 1. i dont get any idea how to split the stiring and make a simple 20*20 matrix out of it !
segments1 = regexp(x{1,1}{i,1},' ','split')
i hope you understand the question !
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Accepted Answer

Bhaskar R on 1 Nov 2019
Edited: Bhaskar R on 1 Nov 2019
No need of reguler expressions here
fun = @str2num;
segments1 = cell2mat(cellfun(fun, x, 'UniformOutput', false));
Produce 20x20 matrix as you require
##### 1 CommentShow -1 older commentsHide -1 older comments
pruth on 1 Nov 2019
thank you !!!

Sign in to comment.

### More Answers (1)

Fabio Freschi on 1 Nov 2019
A = cell2mat(cellfun(@str2num,x,'UniformOutput',false))
##### 1 CommentShow -1 older commentsHide -1 older comments
pruth on 1 Nov 2019
thank you !

Sign in to comment.

### Categories

Find more on Data Type Conversion 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!