Possible Duplicate:
addition of one column with certain condition in another colum, like sumifs of excel
here i want to count the no of 2nd column, with the same conditions in column 1, i m dictating here again,
A=[1 2;2 3;3 4;3 2;4 3;5 4;5 2;6 3;7 2;8 3]
now i want to count no of 2, 3 and 4 in column2, condition is that when column 1 ranges from 0 to 3, 3 to 6, 6 to 9, 9 to 12 like that.
answer is like that
ranges no2, no3, no4
0 to 3-- 2-----1-------1
3 to 6---1------2-------1
6 to 9-- --1-----1------0
help me,,,, waiting for your reply..
With MATLAB you can use logical indexing meaning that you can filter a variable with any number of conditions. For example, if
vec
is any vector and you wish to know how many elements ofvec
are negative you can do the following,So returning to your problem, you can use something like,
You could potentially do something like this:
Another option would be to use the for loop to go through your first column and using a switch statement to pull the appropriate action based on that input.
Update below:
Info on modulus in matlab
Info on switch in matlab