フィルターのクリア

Is there a quick function to make an array whose elements are the sum of the row and column numbers?

2 ビュー (過去 30 日間)
Hello! This should hopefully be a quick and easy question:
Is there a function such that the output of Fun(4) would be:
[2 3 4 5;
3 4 5 6;
4 5 6 7;
5 6 7 8]
i.e. each element of the matrix is equal to its row number + its column number?
I cannot figure out a way to search this question in a concise manner, so I haven't been able to find anything. I know this is fairly simple to code, but I'm curious if there's an already existing function for this. Thanks!

採用された回答

Voss
Voss 2024 年 7 月 26 日
編集済み: Voss 2024 年 7 月 26 日
function out = Fun(n)
    out = (1:n) + (1:n).';
end
  2 件のコメント
Gabriel
Gabriel 2024 年 7 月 26 日
This worked. Sad to see there doesn't seem to be a built-in function for this. Thanks for the help, though :)
Voss
Voss 2024 年 7 月 26 日
You're welcome!
That you can create your own function to do this is perhaps some consolation.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by