Help making a matrix table

조회 수: 5 (최근 30일)
Ben Woods
Ben Woods 2022년 12월 9일
이동: Image Analyst 2022년 12월 10일
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]

답변 (2개)

John D'Errico
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.

David
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
M = 3×3
1 1 1 0 1 1 0 0 1

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by