Help making a matrix table
10 次查看(过去 30 天)
显示 更早的评论
Could someone please help me make a matrix.
I need code that would make an NxN matrix with the pattern of:
if N=4
[1 1 1 1;
0 1 1 1;
0 0 1 1;
0 0 0 1]
0 个评论
回答(2 个)
John D'Errico
2022-12-9
Can you create a matrix of all ones?
Consider the function triu. Read the help. Look at the examples.
0 个评论
David
2022-12-9
移动:Image Analyst
2022-12-10
Hi! Got your back, i'm leaving a code that can do that.
Also, you can consider making a ones matrix with 'ones(N)', and getting the upper triangular with 'triu(M)'.
Hope you find this useful! <3
% With 'N' as the dimention of a square matrix.
M = zeros(N);
for i = 1 : N
for j = i : N
M(i,j) = 1;
end
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!