Squared matrix with elements of the sums of its indices

2 ビュー (過去 30 日間)
Robert Bag
Robert Bag 2021 年 4 月 3 日
編集済み: DGM 2021 年 4 月 3 日
Hi. How can i write squared matrix with elements of the sums of the matrix indices?

回答 (1 件)

DGM
DGM 2021 年 4 月 3 日
編集済み: DGM 2021 年 4 月 3 日
Do you mean to generate a square matrix whose elements are the sum of its subscripts? If so:
If you're using R2016b or newer, you can do
s=5; % size of matrix
A=(1:s) + (1:s)'
otherwise, you can do this in place of line 2:
A=bsxfun(@plus,(1:s),(1:s)')
Of course, this could be extended to non-square matrices:
s=[4 5]; % size of matrix
A=(1:s(2)) + (1:s(1))'

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by