MATLAB: Pattern 1; 2 3; 4 5 6; 7 8 9 10

helpMATLAB

Hello everyone, I wish you healthy days.
How can i do that pattern by using just 'for, if else or while command?
the question is that for example i input number 5, matlab giving me (4 5 6). When i input 7 matlab giving me ( 7 8 9 10)
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17…
Sorry for my bad english and thanks for your help

Best Answer

Try this. It uses the formula
n = input('Input n: ');
a = ceil((-1+sqrt(1+8*n))/2);
y = ((a-1)*a/2+1):(a*(a+1)/2);
disp(y)