Concatenating 2 arrays without changing the dimension

7 ビュー (過去 30 日間)
Swasti Khuntia
Swasti Khuntia 2012 年 6 月 18 日
I want to concatenate 2 arrays of same dimension. And I want to add a blank space in between. When I use ' ', the dimension changes to nx2 while I want that the dimension should remain as nx1. Is there any way out to do this? Any help is welcome !!!!
E.g.: 2 arrays are of dimension n x 1. I want to concatenate them with a blank space. And, after that also I want that the dimension should be n x 1 and not n x 2.
Thanks again !!!!
  4 件のコメント
Jan
Jan 2012 年 6 月 18 日
Please, Swasti, give an explicite example. E.g.
Input:
C1 = {'26-Jun-2993'; '23-Dec-1998'}
C2 = {'17:23:45', '18:10:17'}
Output:
C3 = {'26-Jun-2993 17:23:45'; '23-Dec-1998 18:10:17'}
???
There are several possible types of "an array containing date and time".
Swasti Khuntia
Swasti Khuntia 2012 年 6 月 18 日
The example is perfect for my case.

サインインしてコメントする。

採用された回答

Jan
Jan 2012 年 6 月 18 日
Perhaps you are looking for:
strcat(C1, {' '}, C2)
  4 件のコメント
Walter Roberson
Walter Roberson 2012 年 6 月 19 日
strcat(C1(:), {' '}, C2(:))
Swasti Khuntia
Swasti Khuntia 2012 年 6 月 20 日
Thanks a lot Jan !!!!!

サインインしてコメントする。

その他の回答 (1 件)

Wayne King
Wayne King 2012 年 6 月 18 日
x = randn(10,1);
y = randn(10,1);
z = [x ;y];
or
z = cat(1,x,y);
  5 件のコメント
Wayne King
Wayne King 2012 年 6 月 18 日
Then why is my answer not correct? What do you mean concatenate horizontally? Do you mean a row vector? Then just transpose the result.
Swasti Khuntia
Swasti Khuntia 2012 年 6 月 18 日
In my case, I have a Nx1 date vector and Nx1 time vector. I want to concatenate the two vectors so that the date and time vector is represented in a single vector (i.e., side by side with a blank space). When I try to use ' ' (blank space), the string concatenates no doubt but there are two columns. I hope you get my query.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by