how to convert cell to matrix ?

조회 수: 2 (최근 30일)
pruth
pruth 2019년 11월 1일
댓글: pruth 2019년 11월 1일
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 !

채택된 답변

Bhaskar R
Bhaskar R 2019년 11월 1일
편집: Bhaskar R 2019년 11월 1일
No need of reguler expressions here
fun = @str2num;
segments1 = cell2mat(cellfun(fun, x, 'UniformOutput', false));
Produce 20x20 matrix as you require

추가 답변 (1개)

Fabio Freschi
Fabio Freschi 2019년 11월 1일
A = cell2mat(cellfun(@str2num,x,'UniformOutput',false))

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by