Filter löschen
Filter löschen

Conversion of Cell elements to matrix elements

1 Ansicht (letzte 30 Tage)
Md. Asadujjaman
Md. Asadujjaman am 8 Aug. 2020
Beantwortet: per isakson am 8 Aug. 2020
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?

Akzeptierte Antwort

per isakson
per isakson am 8 Aug. 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

Weitere Antworten (0)

Kategorien

Mehr zu Data Types finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by