Using matlab how to find best row/column in a binary matrix

  • Context: MATLAB 
  • Thread starter Thread starter imtiazgul
  • Start date Start date
  • Tags Tags
    Binary Matlab Matrix
Click For Summary
SUMMARY

This discussion focuses on identifying the best rows and columns in a binary matrix using MATLAB. The matrix in question is of size 100x50, containing only 1s and 0s. The solution involves using the "sum" command to count the number of 1s in each row and column, followed by sorting these counts. The "find" command is then utilized to determine the top three rows and columns with the highest counts of 1s.

PREREQUISITES
  • Understanding of MATLAB programming language
  • Familiarity with matrix operations in MATLAB
  • Knowledge of the "sum" and "find" functions in MATLAB
  • Basic sorting techniques in programming
NEXT STEPS
  • Explore advanced MATLAB matrix manipulation techniques
  • Learn about MATLAB's "sort" function and its options
  • Investigate performance optimization for large matrices in MATLAB
  • Study additional statistical methods for analyzing binary data
USEFUL FOR

This discussion is beneficial for MATLAB programmers, data analysts, and anyone working with binary matrices who seeks to efficiently identify key data points within their datasets.

imtiazgul
Messages
1
Reaction score
0
Hello all
i need help in finding the best row/column in a binary matrix.
suppose i have a matrix of size 100*50 containing only 1s and 0s, how can i find (using matlab)which row or column has highest number of ones? zeros and ones are randomly distributed in the matrix.
i want to find best three rows or coloumns in the matrix
 
Last edited:
Physics news on Phys.org
Count the number of 1's in each row and column. Since you have only binary values, you can use "sum" command. Sort the rows and columns. Using "find" command find the row and column that contains the highest number of 1s
Let a be the given matrix

clear all
r=size(a,1); %find no. of rows
c=size(a,2); %find no. of columns
for i=1:r
nr(i)=sum(a(i,:)); %find no of 1s in each row
end
for i=1:c
nc(i)=sum(a(:,i)); %find no of 1s in each column
end
nrs=sort(nr); % sorting row
ncs=sort(nc); %sorting column
% finding best three rows
br1=find(nr==nrs(r)); %1st best row
if length(br1)==1
br2=find(nr==nrs(r-1));%2nd best row
if length(br2)==1
br3=find(nr==nrs(r-2));%3rd best row
else % remaining lines are meant to overcome the multiple rows of same highest 1s
br3=br2(1,2); % I hope it is self understandable refer help of find command
br2=br2(1,1);
end
end
if length(br1)==2
br2=br1(1,2);
br1=br1(1,1);
br3=find(nr==nrs(r-2));
end
if length(br1)==3
br2=br1(1,2);
br3=br1(1,3);
br1=br1(1,1);
endNow br1,br2 and br3 are best three rows. Repeat the same to find best three columns.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K