#Day67 #100DaysChallenge- Matlab Loops| Finding Length of a vector
#Day67-Finding Length of a vector
Task:
Write a code to find length of a vector
a=1:1:100
length=100.
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.
a=1:1:100
length=100.
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.
Matlab code
function length_vec=lengthofavector(n)
length_vec
=0;
while ~isempty(n)
length_vec = length_vec+1;
n(1)=[];
end
>> n=1:2:100
n =
Columns 1 through 21
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41
Columns 22 through 42
43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83
Columns 43 through 50
85 87 89 91 93 95 97 99
>> length_vec=lengthofavector(n)
length_vec =
50
Free Codes: youtube.com/castorclasses
No comments