Conversion of Cell elements to matrix elements

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

per isakson
per isakson il 8 Ago 2020
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

Più risposte (0)

Categorie

Scopri di più su Data Types in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by