fill column elements with the column number?

2 ビュー (過去 30 日間)
Dmitry Timofeev
Dmitry Timofeev 2020 年 9 月 14 日
編集済み: madhan ravi 2020 年 9 月 14 日
How can I fill column elements with the column number. First column contains only 1, second only 2, third only 3, etc.
  1 件のコメント
Dmitry Timofeev
Dmitry Timofeev 2020 年 9 月 14 日
Is it possible to do this without cycle? I mean without 'for'?

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

採用された回答

Hayden Garmon
Hayden Garmon 2020 年 9 月 14 日
編集済み: Hayden Garmon 2020 年 9 月 14 日
m=5;% m is length of columns
n=4;% n is number of columns
for i =1:n
A(:,i)=ones(m,1)*i ;
end
A =
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
  4 件のコメント
Dmitry Timofeev
Dmitry Timofeev 2020 年 9 月 14 日
Thanks!
madhan ravi
madhan ravi 2020 年 9 月 14 日
編集済み: madhan ravi 2020 年 9 月 14 日
+1
A = ones(m, 1) * ii
%or
A = repmat(ii, m, 1)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDynamic System Models についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by