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

Need help with matlab code: Given variable g that contains a row vector of any s

ID: 2074871 • Letter: N

Question

Need help with matlab code:

Given variable g that contains a row vector of any size, assign to variable h the contents of g with the last element removed

Examples:

Given variable g that contains a row vector of any size, assign to variable h the contents of g with the last element removed Examples: Input g - [8 1 -9] Output h = [8 1] Input g = [3 18-406-5] Output h [3 1 8-4 0 6] Your Function C Reset MATLAB Documentation function h = ROWTrunc(g) 31 %leave this line as is h=g; sAdd a line of code below to change the contents of h, so that it contains the same elements of g but with the last element removed. 6 end

Explanation / Answer

function h = RowTrunc(g)
h= g;
[m,n] =size(h);
if m>1
    printf(" g should be row vector ");
   else
     h = h(1:end-1);
   end
end

same above code in current directory with file name as RowTrunc.m

After this, in command window we can you above function as follows

g= [8 -1 9];

h = RowTrunc(g);

output : -

h =

   8   1

g= [3 1 8 -4 0 6 -5 ];

h = RowTrunc(g);

output : -

h =

   3   1   8 -4   0   6