Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MATLAB code to use linear indexing for the following part: Go down the f

ID: 3913269 • Letter: W

Question

Write a MATLAB code to use linear indexing for the following part: Go down the first column and replace each element with the sum of the two prior elements. Then move onto the next column, continuing the summation from the bottom of the last column. Do this until every element in the matrix is replaced (except for the first two elements.

Write a MATLAB code to use linear indexing for the following part Go down the first column and replace each element with the sum of the two prior elements. Then move onto the next column, continuing the summation from the botton of the last columDo this until every element in the matrix is replaced (expecl for the first two elements) theit replac

Explanation / Answer

ScreenShot

------------------------------------------------------------------------------

Code

%sample matrix or array
matrx1=[1 2 3 4 ;4 5 6 7;6 7 8 9;10 11 12 13];
%matrix before updation
disp('Matrix before updation')
matrx1
%find row col size
[row,col]=size(matrx1);
%use loop to get row values of first column
for i=row:-1:3
%set variables to get above values
k1=i-1;
k2=k1-1;
%Replace value of particular index
matrx1(i,1)=(matrx1(k1,1)+matrx1(k2,1));
end
%display updated matrix
disp('Matrix After updation')
matrx1

---------------------------------------------

Output

Matrix before updation
matrx1 =

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

Matrix After updation
matrx1 =

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote