필터 지우기
필터 지우기

Breaking a number up into its powers of ten

조회 수: 2 (최근 30일)
Benjamin
Benjamin 2013년 5월 8일
Tried searching for it, but I don't even know how to phrase the question honestly.
Say I have a number, 421655 for example. I want to create a vector [4 2 1 6 5 5] from it. If Matlab has a function for it, great, but if someone wants to suggest a general algorithmic approach for this problem, I'd be even happier.

채택된 답변

Roger Stafford
Roger Stafford 2013년 5월 9일
"Breaking a number up into its powers of ten" is precisely what 'dec2base' and 'sprintf' undertake to do, except that the results are expressed in character strings rather than numerical digits.
However, it sounds as though you want to understand the techniques involved in this. To simplify matters suppose x is a non-negative integer and you wish to find the decimal digits that are used to express its value. Here is one technique that starts from the least digit and works up from there.
d = [];
b = true;
while b
r = mod(x,10);
x = (x-r)/10;
d = [r,d];
b = (x~=0);
end

추가 답변 (1개)

John D'Errico
John D'Errico 2013년 5월 8일
help dec2base
  댓글 수: 1
Benjamin
Benjamin 2013년 5월 8일
I don't get it. How does that do what I asked?

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

카테고리

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