Q:

Write a function called “makemat” that will receive two row vectors as input arguments, and from them create and return a matrix with two rows. You may not assume that the length of the vectors is known

0

 Write a function called “makemat” that will receive two row vectors as input arguments, and from them create and return a matrix with two rows. You may not assume that the length of the vectors is known. Also, the vectors may be of different lengths. If that is the case, add 0’s to the end of one vector first to make it as long as the other. For example, a call to the function might be:

 >>makemat(1:4, 2:7)

ans =

 1 2 3 4 0 0

 2 3 4 5 6 7

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

makemat.m

function outmat = makemat(v1,v2)

len1 = length(v1);

len2 = length(v2);

if len1 ~= len2

 if len1>len2

 diff = len1-len2;

 addend = zeros(1,diff);

 v2 = [v2 addend];

 else

 diff = len2-len1;

 addend = zeros(1,diff);

 v1 = [v1 addend];

 end

end

outmat = [v1;v2];

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now