필터 지우기
필터 지우기

Conversion of Cell elements to matrix elements

조회 수: 1 (최근 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 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