concatenate each element of two arrays
古いコメントを表示
I have two arrays, can you please help me how can I concatenate each element of both arrays.
e.g. A=['a' 'b' 'c'] B = ['1' '2']
I want ['a1' 'a2' 'b1' 'b2' 'c1' 'c2']
Thanks
1 件のコメント
Shivaputra Narke
2014 年 2 月 1 日
you can do it using for loop
採用された回答
その他の回答 (3 件)
Jan
2014 年 2 月 1 日
A = {'a' 'b' 'c'};
B = {'1' '2'};
C = strcat(repmat(A, 2, 1), repmat(B', 1, 3))
Notice that A and B are cell strings, not char vectors.
1 件のコメント
Azzi Abdelmalek
2014 年 2 月 3 日
Mohit, this also gives you what you want, just add
C(:)'
Jos (10584)
2014 年 2 月 3 日
A=['a' 'b' 'c']
B = ['1' '2']
C = allcomb(A,B)
Wayne King
2014 年 2 月 1 日
Make A and B cell arrays of strings, but B has to be the same length as A so you'll have to repeat the 2
A = {'a','b','c'};
B = {'1','2','2'};
strcat(A,B)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!