A triangular creation in a matrix with the rest zeros
Show older comments
I want to write a code which does the following:
Say its input is 'n = 12' to create a matrix arranged triangularly with the rest zeros (Only use loop), for example:
% code
Input: n = 12
Output: mat = [1 0 0 0
2 3 0 0
4 5 6 0
7 8 9 10
11 12 0 0]
Thank you
4 Comments
Jan
on 20 May 2018
The shape of the non-zero value is not triangular here.
The question sounds like a homework. The forum will not solve it, but if you ask a specific question and post, what you have done so far, you will get assistance here for sure.
Emilia
on 20 May 2018
dpb
on 20 May 2018
What if you were to start with an array of the proper final size containing (let me guess...) zeros, maybe?
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!