how to convert a vector to a number

조회 수: 2 (최근 30일)
Itzik Ben Shabat
Itzik Ben Shabat 2012년 12월 16일
hi lets say i have a vector [1,1,1] is there a function that can convert this to the number 111 ?
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 12월 16일
What should be done if the vector includes values greater than 9?
If the vector starts with values that are 0, what should be the result ?
Itzik Ben Shabat
Itzik Ben Shabat 2012년 12월 16일
the vector does not contain values greater than 9. if it has 0 to the left it ignores them - 009=9, 012=12 etc.
i could write a for loop that calculates this but i was wondering if there is a function.

댓글을 달려면 로그인하십시오.

채택된 답변

José-Luis
José-Luis 2012년 12월 16일
편집: José-Luis 2012년 12월 16일
a = randi(9,1,5);
your_num = sscanf(sprintf('%d',a),'%d');
or
alt_sol = sum(a.*repmat(10,1,numel(a)).^(numel(a)-1:-1:0));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by