Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

#Day66 #100DaysChallenge- Matlab Loops| Flipping a vector

#Day66-Flipping a vector

Task:

Write a code to flip  the given vector
a=[1,2,3,4,5,6,7,8];
b=[8,7,6,5,4,3,2,1];

Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.

Matlab code 


function b= flipingvector(n)
length_n=length(n);
j=1;
for i=1:1:length_n
   
    b((length_n+i)-j)=n(i);
    j=j+2;

end

Sample Input and Output
>> n=1:2:20


n =

     1     3     5     7     9    11    13    15    17    19

>> b= flipingvector(n)

b =

    19    17    15    13    11     9     7     5     3     1

>> n=1:3:40

n =

     1     4     7    10    13    16    19    22    25    28    31    34    37    40

>> b= flipingvector(n)

b =

    40    37    34    31    28    25    22    19    16    13    10     7     4     1



Click here for Video Description


Live Support: t.me/matlabirawen





No comments

Popular Posts