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

Search This Blog

#Day70 #100DaysChallenge- Matlab Loops| Vector Element Accessing

#Day70-Vector Element Accessing

Task:

Write a code to access vector element

a=1:1:10 b=1,3,5,7,9



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 = vectorelements_accessing(x)
inc=1;
for i=1:2:length(x)
    b(inc)=x(i);
    inc=inc+1;
end
end
Sample Input and Output
>> vectorelements_accessing(a)

ans =

     1     3     5     7

>> a

a =

     1     2     3     4     5     6     7     8

>> vectorelements_accessing(b)

ans =

     1     3     5

>> b

b =

     1
     2
     3
     4
     5
     6
  Click here for Video description




No comments

Popular Posts