#Day94#100DaysChallenge- Matlab Loops | Repetition Series
#Day94-Repetition series
Task:
Write a code to print series as shown below
g =
Columns 1 through 19
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6
Columns 20 through 21
6 6
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.
Matlab code
function g=repetition_series(x)
count=1;
for i=1:1:x
for j=1:1:i
g(count)=i;
count=count+1;
end
end
end
Sample Input and Output
>> g=repetition_series(6)
g =
Columns 1 through 19
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6
Columns 20 through 21
6 6
Free Codes: youtube.com/castorclasses
No comments