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

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();