I am trying to create a triangular matrix from a row vector using loops. I know there are built-in commands that makes this easy, but I am a beginner programmer and I want to test this out.
Here is what I've got so far.
function [ a ] = Up( v )
n = length(v);
a = eye(n);
j = 1;
i = 1;
while(i <= n)
while(j <= n)
a(i,j) = v(i, j);
j = j +1;
end
a(i, i +1) = 0;
i = i + 1;
end
My problem is that it shows me the iterative steps, all I want is the final answer. Also, I can only generate the first row.
For instance, if I give you $v = (3, 8, 9)$, I want to be able to return
$$A = \begin{bmatrix} 3 &8 &9 \\ 0&8 &9 \\ 0&0 &9 \end{bmatrix}$$
a(i,j) = v(i, j)toa(i,j) = v(i, j);. The semicolon tells matlab to supress the result. – Daryl Jan 28 '14 at 23:21a(i,j) = v(i, j). The semicolon is used to suppress output. – AnonSubmitter85 Jan 28 '14 at 23:22Upp. – AnonSubmitter85 Jan 28 '14 at 23:25