How can I creat a lower triangular with one vektor avoiding for loops?
Show older comments
Hello everybody,
i have one vektor (let's call it g) with a dimension N and I need to create a NxN lower triangular matrix where the first column is g from 1 to N,
the second column starts with a zero in the first row and then from second row starts again with g from 1 to (N-1)
the third column starts with zeros in the first and second row, followed by g from entry 1 to (N-2)...
and so on...
Example:
g=[1 2 3]
M=[1 0 0; 2 1 0; 3 2 1]
____
My Code right now has a for loop, however i need to avoid this.
function M=ltmatrix(g)
for a=1:lenght(g)
M(a:length(g),a)=g(1:length(g)+1-a);
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!