converting from cell 2 matrix
古いコメントを表示
i have a cell like
a{1,1}={160;45;58;89}% in the form of 1*50char a{2,1}={160;45;58;89}% in the form of 1*50char a{3,1}={160;45;58;89}% in the form of 1*50char a{4,1}={160;45;58;89}% in the form of 1*50char
like this i have a cellsize of 50000 rows(a{50000,1})
what is the best way to convert elements inside cell to matrix form
eg o/p : desired matrix to be
b(1,:)= 160 45 58 89 b(2,:)= 160 45 58 89 b(3,:)= 160 45 58 89 b(4,:)= 160 45 58 89
problem here is the forloop is taking lot of time to convert to serired matrix way
採用された回答
その他の回答 (1 件)
Azzi Abdelmalek
2012 年 11 月 15 日
b=cell2mat(a)
7 件のコメント
Azzi Abdelmalek
2012 年 11 月 15 日
a={'12' '123' '4';'5' '45' '0.1'}
b=cellfun(@str2double,a)
Azzi Abdelmalek
2012 年 11 月 15 日
編集済み: Azzi Abdelmalek
2012 年 11 月 15 日
what is the problem with
b=cellfun(@str2double,a)
I gave just an example, it should work with your case
Azzi Abdelmalek
2012 年 11 月 15 日
please give a sample of your data
Azzi Abdelmalek
2012 年 11 月 15 日
編集済み: Azzi Abdelmalek
2012 年 11 月 15 日
If you mean
a={'12 123 4';'5 45 0.1'}
b=cell2mat(cellfun(@str2num,a,'un',0))
Azzi Abdelmalek
2012 年 11 月 15 日
編集済み: Azzi Abdelmalek
2012 年 11 月 15 日
I said provide a small example, a=?
a={'12 123 4';'5 45 0.1'}
or
a={'12' '123' '4';'5' '45' '0.1'}
or what?
Azzi Abdelmalek
2012 年 11 月 15 日
編集済み: Azzi Abdelmalek
2012 年 11 月 15 日
b=cell2mat(cellfun(@(x) cellfun(@str2double, regexp(x,';','split')),a,'un',0))
Jan
2012 年 11 月 15 日
@Azzi: str2double accepts cell strings as input. Therefore I'd omit at least the innermost cellfun. cell2mat contains an expensive loop. Therefore it is most likely naticably faster to create this loop manually, because this will reduce the amount of temporarily used memory.
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!