How can I build a matrix with an increasing number of terms in each row?
4 次查看(过去 30 天)
显示 更早的评论
I'm trying to build a matrix which has an increasing number of summed terms in each row.
For example n = 1 would be the first row, the sum of n = 1 and n = 2 in the second row and so forth, all the way up through n = 50.
I believe the matrix should come out like
1
1 2
1 2 3
0 个评论
采纳的回答
更多回答(1 个)
Image Analyst
2021-10-14
If you're willing to use a cell array instead of a regular matrix, you can do this:
n = 50;
ca = cell(n, n)
for row = 1 : n
for col = 1 : row
ca{row, col} = sum(1:col);
end
end
The "unused" cells will still be there but they will have null inside them.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!