MATLAB Programming 4 For the Matrix M magic4 which is M 16

MATLAB Programming:

4. For the Matrix, M = magic(4) which is M = [16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1]

(a) Delete the elements in the last row

(b) Delete the elements in the last column

(c) Replace the elements in the first row with all zeros

(d) Replace the element in Row=2 and Column=2 with 100

(e) Copy the elements in the first column into the second column

Solution

M = [16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1];
disp(M);
disp(\'delete the elements in the last row:\')
M(4,:)=[];%delete the elements in the last row
disp(M);
disp(\'delete the elements in the last column:\')
M(:,4)=[];%delete the elements in the last column
disp(M);
disp(\'Replace the elements in the first row with all zeros:\')
M(1,:)=zeros;%Replace the elements in the first row with all zeros
disp(M);
disp(\'Replace the element in Row=2 with 100:\')
M(2,:)=[1 0 0];%Replace the element in Row=2 with 100
disp(M);
disp(\'Replace the element in column=2 with 100:\')
M(:,2)=[1 0 0];%Replace the element in Column=2 with 100
disp(M);
disp(\' Copy the elements in the first column into the second column:\')
M(:,2)=M(:,1);% Copy the elements in the first column into the second column
disp(M);

Output:

16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1

delete the elements in the last row:
16 2 3 13
5 11 10 8
9 7 6 12

delete the elements in the last column:
16 2 3
5 11 10
9 7 6

Replace the elements in the first row with all zeros:
0 0 0
5 11 10
9 7 6

Replace the element in Row=2 with 100:
0 0 0
1 0 0
9 7 6

Replace the element in column=2 with 100:
0 1 0
1 0 0
9 0 6

Copy the elements in the first column into the second column:
0 0 0
1 1 0
9 9 6

MATLAB Programming: 4. For the Matrix, M = magic(4) which is M = [16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1] (a) Delete the elements in the last row (b) Delete
MATLAB Programming: 4. For the Matrix, M = magic(4) which is M = [16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1] (a) Delete the elements in the last row (b) Delete

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site