Create upper triangular matrix using for loop in matlab

v = 1:6;
n = round((sqrt(8 * numel(v) + 1) - 1) / 2);
M = zeros(n, n);
c = 0;
for i2 = 1:n
for i1 = 1:i2
c = c + 1;
M(i1, i2) = v(c);
end
end
I found this code to make an upper triangular matrix, but I don't understand what the code is trying to say to make it work can someone explain to me

2 Kommentare

Or could you tell me another way to make an upper triangular array with a for loop

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 4 Jan. 2021

Kommentiert:

am 4 Jan. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by