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 件のコメント
pruth
pruth 2019 年 11 月 1 日
thank you !!!

サインインしてコメントする。

その他の回答 (1 件)

Fabio Freschi
Fabio Freschi 2019 年 11 月 1 日
A = cell2mat(cellfun(@str2num,x,'UniformOutput',false))
  1 件のコメント
pruth
pruth 2019 年 11 月 1 日
thank you !

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by