how to concatenate two vectors with different types
2 次查看(过去 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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Hypothesis Tests 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!