Hey,
I want to create a matrix out of one vector.
v=[1,2,3,4]
And the matrix should have the form
M= 1 2 3 4
2 2 3 4
3 3 3 4
4 4 4 4
Is there an easy solution for that?
Thanks

 採用された回答

Voss
Voss 2022 年 6 月 12 日

0 投票

v=[1,2,3,4];
N = numel(v);
idx = max(1:N,(1:N).');
M = v(idx)
M = 4×4
1 2 3 4 2 2 3 4 3 3 3 4 4 4 4 4

2 件のコメント

Johannes Reiers
Johannes Reiers 2022 年 6 月 12 日
Thanks a lot
Voss
Voss 2022 年 6 月 12 日
You're welcome!

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

その他の回答 (1 件)

Jan
Jan 2022 年 6 月 12 日

0 投票

v = [1,2,3,4];
max(v, v.')
ans = 4×4
1 2 3 4 2 2 3 4 3 3 3 4 4 4 4 4

カテゴリ

ヘルプ センター および File ExchangeElementary Math についてさらに検索

製品

リリース

R2022a

タグ

質問済み:

2022 年 6 月 12 日

コメント済み:

2022 年 6 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by