Conversion of Cell elements to matrix elements

2 ビュー (過去 30 日間)
Md. Asadujjaman
Md. Asadujjaman 2020 年 8 月 8 日
回答済み: per isakson 2020 年 8 月 8 日
I have the following cell:
x{1,1}={1,5,3}
x{1,2}={2}
x{1,3}={}
x{2,1}={2,4}
x{2,2}={5,3,1}
x{2,3}={}
Now, I want to convert the cell element to a matrix, where the elements of a cell will make one number together seequentially. e.g., the elements 1,5,3 will make a number 153. The output matrix will be as follows:
output = [153 2 0
24 531 0]
How can I get the output matrix from the above cell?

採用された回答

per isakson
per isakson 2020 年 8 月 8 日
Matlab magic
%%
x{1,1}=[1,5,3];
x{1,2}=[2];
x{1,3}=[];
x{2,1}=[2,4];
x{2,2}=[5,3,1];
x{2,3}=[];
%%
cellfun( @(v) sum(v.*(10.^(numel(v)-1:-1:0))), x, 'uni',true )
outputs
ans =
153 2 0
24 531 0

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by