## how to replace elements in top third, middle third, and bottom third of matix

This question is soft-locked: new answers that are equivalent to already posted answers may be deleted without prior notice.

My task is the following:

Write a function called trio that takes two positive integer inputs n and m. The function returns a 3n-by-m matrix called T. The top third of T (an n by m submatrix) is all 1s, the middle third is all 2-s while the bottom third is all 3-s. See example below:

M = trio(2,4)

M =

1 1 1 1

1 1 1 1

2 2 2 2

2 2 2 2

3 3 3 3

3 3 3 3

This is the code that I wrote, but it only works for T = trio (4,3). I want my code to work for any input of n,m.

function T = trio (n, m)

T = randi (10, (3 * n) , m);

T ( 1:n , ๐ = 1;

T ( (n+1):(end-(n-1)) , ๐ = 2;

T ( (n+3):end, ๐ = 3;

end

How is it possible to call out only top third, middle third, and bottom third of any matrix?

Thank you in advance.This question is soft-locked: new answers that are equivalent to already posted answers may be deleted without prior notice.

My task is the following:

Write a function called trio that takes two positive integer inputs n and m. The function returns a 3n-by-m matrix called T. The top third of T (an n by m submatrix) is all 1s, the middle third is all 2-s while the bottom third is all 3-s. See example below:

M = trio(2,4)

M =

1 1 1 1

1 1 1 1

2 2 2 2

2 2 2 2

3 3 3 3

3 3 3 3

This is the code that I wrote, but it only works for T = trio (4,3). I want my code to work for any input of n,m.

function T = trio (n, m)

T = randi (10, (3 * n) , m);

T ( 1:n , ๐ = 1;

T ( (n+1):(end-(n-1)) , ๐ = 2;

T ( (n+3):end, ๐ = 3;

end

How is it possible to call out only top third, middle third, and bottom third of any matrix?

Thank you in advance.ย This question is soft-locked: new answers that are equivalent to already posted answers may be deleted without prior notice.

My task is the following:

Write a function called trio that takes two positive integer inputs n and m. The function returns a 3n-by-m matrix called T. The top third of T (an n by m submatrix) is all 1s, the middle third is all 2-s while the bottom third is all 3-s. See example below:

M = trio(2,4)

M =

1 1 1 1

1 1 1 1

2 2 2 2

2 2 2 2

3 3 3 3

3 3 3 3

This is the code that I wrote, but it only works for T = trio (4,3). I want my code to work for any input of n,m.

function T = trio (n, m)

T = randi (10, (3 * n) , m);

T ( 1:n , ๐ = 1;

T ( (n+1):(end-(n-1)) , ๐ = 2;

T ( (n+3):end, ๐ = 3;

end

How is it possible to call out only top third, middle third, and bottom third of any matrix?

Thank you in advance.ย matrix manipulation, homework, soft-lockย MATLAB Answers โ New Questions

โ