Does anybody know?

조회 수: 5 (최근 30일)
Ben Davis
Ben Davis 2012년 3월 5일
A line of code i could use for my function so when i insert a vector such as [1 2 3 4], the function i am making see's it as the value 1234(one thousand, two hundred and thirty four) instead? Thanks :)
  댓글 수: 1
Andrei Bobrov
Andrei Bobrov 2012년 3월 6일
c = [1 2 3 4]
out = c*10.^(numel(c)-1:-1:0).'

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

채택된 답변

Walter Roberson
Walter Roberson 2012년 3월 5일
str2double(sprintf('%d',V))
or
str2double(char(V+'0'))
which should be more efficient.
Warning: if your vectors might have 15 to 19 elements, then there would be additional work involved in order to get the correct integer. From 19 elements up, only an approximation of the integer can be produced.
  댓글 수: 9
Walter Roberson
Walter Roberson 2012년 3월 7일
If you need to handle more than 19 elements, then you are going to have to write a whole new function based on very different computation principles. I think it likely that it was intended that you use those computation principles right from the beginning.
Your algorithm will need to implement "long division" or the equivalent.
Ben Davis
Ben Davis 2012년 3월 7일
hoooray -_-

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

추가 답변 (1개)

the cyclist
the cyclist 2012년 3월 5일
x = [1 2 3 4];
str2num(num2str(x')')
  댓글 수: 1
Ben Davis
Ben Davis 2012년 3월 5일
Sorry i deleted my previous reply, what i meant to say is that this only works for when x and y are the same size vector (x=[2 2 2 2], y=[1 1 1 1]. Sorry for being a pain, but do you know what i could do to my code so that it will work even if x and y do not contain the same amount of digits inside of them. My functions plans on dividing x by y.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by