how to concatenate two vectors with different types

조회 수: 2 (최근 30일)
bay rem
bay rem 2015년 12월 30일
답변: Walter Roberson 2015년 12월 30일
i have two vectors: vector1= [ 23 54 67 987] vector2=['test']
is there a way two concatenate those two vectors and obtain: [ 23 54 67 987 'test']
thank you in advance

채택된 답변

Walter Roberson
Walter Roberson 2015년 12월 30일
No.
You can use [num2cell(vector1),vector2] to get {[23] [54] [67] [987] 'test'}
or {vector1, vector2} to get {[23 54 67 987] 'test'}
both of those are cell arrays.
You can also use [sprintf('%d ', vector1), vector2] to get '23 54 67 987 test' which is a string.
All three have their use, but the first of those with num2cell is the one you probably want to use if you are trying to create values to write with excel, and the last of them with sprintf is the one you probably want to use if you are formatting a single line for display purposes. (If you are formatting multiple lines for display purposes then you will usually end up using the first version together with a "trick" for sprintf)

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by