For loop for matrix with increasing numbers
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2016-3-7
Try this:
theNumber = 1;
for col = 1 : 8
for row = 1 : 7
a(row, col) = theNumber;
theNumber = theNumber + 4;
end
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Argument Definitions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!