fill column elements with the column number?

2 Ansichten (letzte 30 Tage)
Dmitry Timofeev
Dmitry Timofeev am 14 Sep. 2020
Bearbeitet: madhan ravi am 14 Sep. 2020
How can I fill column elements with the column number. First column contains only 1, second only 2, third only 3, etc.
  1 Kommentar
Dmitry Timofeev
Dmitry Timofeev am 14 Sep. 2020
Is it possible to do this without cycle? I mean without 'for'?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Hayden Garmon
Hayden Garmon am 14 Sep. 2020
Bearbeitet: Hayden Garmon am 14 Sep. 2020
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 Kommentare
Dmitry Timofeev
Dmitry Timofeev am 14 Sep. 2020
Thanks!
madhan ravi
madhan ravi am 14 Sep. 2020
Bearbeitet: madhan ravi am 14 Sep. 2020
+1
A = ones(m, 1) * ii
%or
A = repmat(ii, m, 1)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Dynamic System Models finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by