Conversion of Cell elements to matrix elements

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Data Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by