From: Jose on 28 Dec 2009 12:20 Hello, I have a vector, and I need to count how many times a determined value in found inside a vector. for example if I have the vector: V=[ 2, 5, 4, 2, 0, 9, 8, 0 ] the value "0" in found twice. Which function can I use to count how many times a determined values is found? thank you very much!
From: Andy on 28 Dec 2009 12:54 "Jose " <mylordjose(a)hotmail.com> wrote in message <hhapcl$jp7$1(a)fred.mathworks.com>... > Hello, > > I have a vector, and I need to count how many times a determined value in found inside a vector. > > for example if I have the vector: V=[ 2, 5, 4, 2, 0, 9, 8, 0 ] > the value "0" in found twice. > Which function can I use to count how many times a determined values is found? > > thank you very much! sum(V==0);
From: Vince Petaccio on 28 Dec 2009 12:56 "Jose " <mylordjose(a)hotmail.com> wrote in message <hhapcl$jp7$1(a)fred.mathworks.com>... > Hello, > > I have a vector, and I need to count how many times a determined value in found inside a vector. > > for example if I have the vector: V=[ 2, 5, 4, 2, 0, 9, 8, 0 ] > the value "0" in found twice. > Which function can I use to count how many times a determined values is found? > > thank you very much! You can use the find function to create a list of indices of a particular value in the vector, then determine the "count" based on the length of the index vector. Ex. V=V=[ 2, 5, 4, 2, 0, 9, 8, 0 ]; ind = find(V==0) ans = 5 8 length(ind) ans = 2 To make this quicker, num_zeros = length(find(V==0)) num_zeros = 2 -Vince
From: ImageAnalyst on 28 Dec 2009 13:23 Here's a third way, using nnz -- a function to find the number of non- zeros: % Create some sample data. V=[ 2, 5, 4, 2, 0, 9, 8, 0 ] % We don't have to, but let's use a variable for the number to look for. valueToLookFor = 0; % Use whatever value you want. % Count how many times it occurs. numOccurrences = nnz(V == valueToLookFor)
From: Jose on 28 Dec 2009 14:12 Thank you very much for all the anwers!. It helped me very much!! Jose
|
Pages: 1 Prev: rgb2hsv functions mathmatical formula Next: VisualDSP link fails |