Write a function called generaterandomvectorcorrupted that i

Write a function called generate_random_vector_corrupted that is identical in every way to (1), except that every third element of the returned vector is zero. In your code, show how to do this both using a for loop and using Matlab vector indexing.

Solution

mat lab code;

EDU>> A=[1 2 3 4 5 6 7 8 9 10];
N=3;
B=A(1:N:length(A))

      1 2 4 5 7 8

*******************************

Use a mask. Let\'s say you have

Then

will be a vector of the same length as A containing the repeated sequence 0 1 2 3 4. You want everything from A except the elements where m == 4, i.e.

will result in

similarly 3 can be done

*********************************

say A is your vector

then

can follow any of the ways

Write a function called generate_random_vector_corrupted that is identical in every way to (1), except that every third element of the returned vector is zero.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site