フィルターのクリア

Convert three array into one matrix.

2 ビュー (過去 30 日間)
DAT VUONG
DAT VUONG 2017 年 8 月 28 日
コメント済み: DAT VUONG 2017 年 8 月 30 日
I have two array 1xn (A1....An), 1xm(B1...Bm) and value Z. I want to create one matrix nxm rows and 3 columns as follow:
A1 B1 Z,
A1 B2 Z,
...
A1 Bm Z,
A2 B1 Z,
...
An B1 Z,
...
An Bm Z
I do not know how to create this. Could you please help me to solve this problem. Thanks for your help.

採用された回答

Stephen23
Stephen23 2017 年 8 月 28 日
編集済み: Stephen23 2017 年 8 月 28 日
>> A = 1:3;
>> B = 4:7;
>> Z = 8;
>> [Am,Bm,Zm] = meshgrid(A,B,Z);
>> [Am(:),Bm(:),Zm(:)]
ans =
1 4 8
1 5 8
1 6 8
1 7 8
2 4 8
2 5 8
2 6 8
2 7 8
3 4 8
3 5 8
3 6 8
3 7 8

その他の回答 (2 件)

KL
KL 2017 年 8 月 28 日
編集済み: KL 2017 年 8 月 28 日
n = 3;
m = 5;
A = rand(1,n)
B = rand(1,m)
Z = 10;
res = [reshape(repmat(A,m,1),n*m,1) repmat(B',n,1) Z*ones(n*m,1)]
  1 件のコメント
DAT VUONG
DAT VUONG 2017 年 8 月 30 日
Thanks for your help!

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


DAT VUONG
DAT VUONG 2017 年 8 月 28 日
Thanks Stephen Cobeldick!

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by