fill column elements with the column number?

2 visualizzazioni (ultimi 30 giorni)
How can I fill column elements with the column number. First column contains only 1, second only 2, third only 3, etc.

Risposta accettata

Hayden Garmon
Hayden Garmon il 14 Set 2020
Modificato: Hayden Garmon il 14 Set 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 Commenti
madhan ravi
madhan ravi il 14 Set 2020
Modificato: madhan ravi il 14 Set 2020
+1
A = ones(m, 1) * ii
%or
A = repmat(ii, m, 1)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Dynamic System Models in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by