Two vectors into matrix with an opeartion?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi everybody,
I'd like to create a matrix from 2 vectors with a subtraction.
a=[0,1,2,3]
b=[6,7,8,9]
The operation is b-a, so the resulting matrix should look like this
6 5 4 3
7 6 5 4
8 7 6 5
9 8 7 6
Additional question: Is it possible to place the results underneath the first row of Vector a
0 1 2 3
6 5 4 3
7 6 5 4
8 7 6 5
9 8 7 6
Thank you for your help in advance
Christian
0 件のコメント
採用された回答
Alan Stevens
2020 年 8 月 24 日
Like this:
a = [0 1 2 3];
b = [6; 7; 8; 9]; % Note that b is a column vector and a is a row vector
A = repmat(a,4,1)
A =
0 1 2 3
0 1 2 3
0 1 2 3
0 1 2 3
>> m = b - A
m =
6 5 4 3
7 6 5 4
8 7 6 5
9 8 7 6
>> m = [a; m]
m =
0 1 2 3
6 5 4 3
7 6 5 4
8 7 6 5
9 8 7 6
2 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!