For loop for matrix with increasing numbers
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
laura9510
am 7 Mär. 2016
Bearbeitet: laura9510
am 7 Mär. 2016
I'm trying to use a for loop to create a 7x8 matrix that increases by 4 for each number (starting at 1).
So far I have something that goes
for
k = 1:8
a(k)=4*k;
end
just to create the first row... how would I go about adding more rows that keep adding increasing elements?
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 7 Mär. 2016
Try this:
theNumber = 1;
for col = 1 : 8
for row = 1 : 7
a(row, col) = theNumber;
theNumber = theNumber + 4;
end
end
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation 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!