counting the number of elements under multiple conditions
    25 views (last 30 days)
  
       Show older comments
    
    Alexandra Brian
 on 1 Feb 2017
  
    
    
    
    
    Commented: Alexandra Brian
 on 3 Feb 2017
            Hi there,
I need to count the number of elements in column y that confirm two conditions:
- When the column x is greater than 0.
- When column y is greater than 0.
clear all 
rB5_SMA50Diff14 = xlsread('xy.xlsx');
x = xlsread('xy.xlsx', 'B:B');
y = xlsread('xy.xlsx', 'A:A');
  rows = x(:,5)>0; %Logical vector with the rows which satisfy all conditions.
  if any(rows) % True if there is at least 1 row which meats the condition.
   Winners= numel(y(rows)>0); %Counts the number of elements that are greater than 0.
end
My code returns the total number of elements in column y that fall under rows where column x > 0.
Can you please help me find the number of elements in column y that are > 0 and correspond to column x when column x > 0.
Best, A
0 Comments
Accepted Answer
  Image Analyst
      
      
 on 2 Feb 2017
        Assuming x and y are 1-D column vectors and are the same length, why can't you just get the count like this:
Winners = sum(x>0 & y>0)
More Answers (0)
See Also
Categories
				Find more on Propagation and Channel Models in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
