Reputation: 15
I have a 100*20 matrix called pr (power receive in my case) the 100 represent number of users and 20 number of antennas each user receive certain power from the 20 antennas.(more than one user could receive power from the same antenna). then i find the maximum power each user receive and put it in a 100*1 vector If this maximum values greater than (-112) counter increase. I need to create new vector 20*1 where 20 is the antennas number and count the number of users that receive power greater than(-112) for each antenna
[master_ant,id]=max(pr,[],2); %find vector of max values and vector of the corresponding index
for i=1:100
if(master_ant(i)>=-112) %check the rang
covered_user=covered_user+1;%counter increment
end
end
i tried this
[master_ant,id]=max(pr,[],2);
for i=1:100
if(master_ant(i)>=-112)
covered_user(id)=covered_user(id)+1;
Upvotes: 0
Views: 121
Reputation: 4558
The easiest way to do this is to consider another approach. The function sum
, can actually (and is supposed to) do all the job for you.
a = randi([-130, -60],100,20); % Example matrix
covered_user = sum(a>=-112); % One-liner solution
Upvotes: 2