suppose that a = [ 1 2 3; 4 5 6; 7 8 9]. use it to create b = [ 7 8 9; 7 8 9; 4 5 6;] in matlab

One way to do this is using matrix indexing and concatenation in MATLAB. We can select the last two rows of matrix a and concatenate it with the last row of a to form the desired matrix b. Here's the code:

main.m
a = [1 2 3; 4 5 6; 7 8 9];
b = [a(3,:); a(3,:); a(2,:);];
58 chars
3 lines

In this code, a(3,:) selects the third row of matrix a, while a(2,:) selects the second row of matrix a. The semicolon (;) is used for concatenation.

Now, the matrix b is equal to [7 8 9; 7 8 9; 4 5 6].

related categories

gistlibby LogSnag