I want to combine two columns. Here is the example of probleme: A column has lot of number like 20100101;20100102... .B column has the same amount of numbers like 020510000;020510040... . I want to aggregate A and B columns to have one column like 2010010120510000;20100102020510040... . That every A(x) would be in the same row with B(x). Thank you very much.

 채택된 답변

Star Strider
Star Strider 2015년 9월 17일

0 개 추천

One approach:
A = [20100101;20100102];
B = [020510000;020510040];
ABS = sprintf('%d%09d\n', [A, B]'); % String Representation
ABN = str2num(sprintf('%d%09d\n', [A, B]')) % Numeric Conversion

댓글 수: 2

Paulius Vaikasas
Paulius Vaikasas 2015년 9월 17일
Thank you.
Star Strider
Star Strider 2015년 9월 17일
My pleasure!

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

추가 답변 (1개)

James Tursa
James Tursa 2015년 9월 17일
편집: James Tursa 2015년 9월 17일

0 개 추천

This is how one would do it if A and B are doubles:
C = A*1e8 + B;
However, each of A and B has 8 decimal digits, so the result of this calculation will have 16 decimal digits. That is right at the limit of what a double precision value can hold, and may even be beyond depending on the actual values involved. So this might not work and you may need a different method.
If A and B are actually char arrays, then it is simply:
C = [A,B];

카테고리

도움말 센터File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

질문:

2015년 9월 17일

댓글:

2015년 9월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by