필터 지우기
필터 지우기

join numbers in vector

조회 수: 4 (최근 30일)
gwar
gwar 2013년 7월 23일
I have a row vector with 7 numbers, e.g. 13 30 44 12 44 23 12. I want to join all these numbers into a single number, or 13304412442312. I have not been able to find a method to do this. Can anyone please suggest a method to do this without using a for loop.

채택된 답변

kjetil87
kjetil87 2013년 7월 23일
편집: kjetil87 2013년 7월 23일
x=[13 30 44 12 44 23 12];
stringX=num2str(x);
stringX=stringX(stringX~=' '); % remove the space
x2=str2num(stringX);
  댓글 수: 3
kjetil87
kjetil87 2013년 7월 23일
agreed , int64 is better.
dpb
dpb 2013년 7월 23일
Gives more dynamic range than double at cost of less flexible to other operations. Of course, OP will eventually run out of range there, too, if continues to increase the size of the vector...

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

추가 답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 23일
편집: Azzi Abdelmalek 2013년 7월 23일
a=[13 30 44 12 44 23 12]
b=strrep(num2str(a),' ','')
% This is a string, if you to get a number
b=str2num(strrep(num2str(a),' ',''))

dpb
dpb 2013년 7월 23일
>> sscanf(sprintf('%d',v),'%lu')
ans =
13304412442312
>> whos ans
Name Size Bytes Class Attributes
ans 1x1 8 uint64
>> sscanf(sprintf('%d',v),'%li')
ans =
13304412442312
>> whos ans
Name Size Bytes Class Attributes
ans 1x1 8 int64
>>

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by