How can I concatenate two or more arrays without using num2str?

조회 수: 1 (최근 30일)
Adriano
Adriano 2017년 2월 20일
답변: Adriano 2017년 2월 21일
For example if I have two vertical arrays:
A = [1;2] B = [3;4]
I need this output:
C = [13; 24]
The problem is that my arrays have many rows, thus num2str is too slow. What can I do? Thanks!!!
  댓글 수: 2
Adam
Adam 2017년 2월 20일
I can't help but think of the joke of someone asking for directions to somewhere and being told 'Well, if I were you I wouldn't start from here'.
There may be better suggestions based on the wider context of the code than already having A and B defined.
John D'Errico
John D'Errico 2017년 2월 20일
Good response by Adam.

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

채택된 답변

John D'Errico
John D'Errico 2017년 2월 20일
편집: John D'Errico 2017년 2월 20일
The most obvious solution is to appreciate how a number is constructed in decimal form. So, rather than convert to characters, then concatenate, and then go back in to numeric form, simply use base 10.
C = 10*A + B;
  댓글 수: 3
John D'Errico
John D'Errico 2017년 2월 20일
True. I expect that whenever I see an example with one digit integers, the real problem is always more complex. :)
Walter Roberson
Walter Roberson 2017년 2월 20일
I would max(1,log10(max(abs(B))))
though the desired outcome is not clear for negative values.

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

추가 답변 (1개)

Adriano
Adriano 2017년 2월 21일
Many thanks!!!!

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by