20782

Finding indexes, intersection and then ranking in a matrix?

Question:

I have a matrix like as follows:

a = [1 0 0 0 0 0 0; 1 1 0 0 0 0 0; 1 0 1 0 0 0 0; 1 1 0 1 1 0 0; 1 1 0 1 1 0 0; 1 0 1 0 0 1 1; 1 0 1 0 0 1 1]

of which i wish to create following table:

X - For each Rows index of cols having 1 Y - For each cols index of rows having 1 Z - Intersection set S.No X Y Z Rank(Comparing X & Z) 1 1 1,2,3,4,5,6,7 1 I 2 1,2 2,4,5 2 II 3 1,3 3,6,7 3 II 4 1,2,4,5 4,5 4,5 III 5 1,2,4,5 4,5 4,5 III 6 1,3,6,7 6,7 6,7 III 7 1,3,6,7 6,7 6,7 III

Of the above table, X and Y columns have been easily found with the help of Matlab code as provided by Sir Luis Mendo to my previous question. Code was as follows:

[ii jj] = find(a); %// find row and col indices (ii and jj respectively) rows = accumarray(ii,jj,[], @(v) {sort(v).'}); %'// group jj as per ii, and sort cols = accumarray(jj,ii,[], @(v) {sort(v).'}); %'// group ii as per jj, and sort rows{:} cols{:}

Now i wish to find intersection set i.e. Z but i m not able to find using intersection command.

Further Ranking is to be done on comparing columns X and Z in such a manner that with minimum of elements in both columns, maximum of common elements should be there and each time that common element should be emitted from the whole X column for further comparison so that again with minimum of elements in both sets max common elements can be found.

Please help.

Answer1:

For the intersection, just work with a & a.':

[ii jj] = find(a & a.'); z = accumarray(ii,jj,[], @(v) {sort(v).'});

Recommend

  • How to make a matlab legend recognize multiple scatter plots?
  • Error building MEX-files (MATLAB 2012a) on Kubuntu '/usr/bin/ld: cannot find -lstdc++'
  • integration of function in modelica
  • Jquery UI Sortable, move item automatically
  • Python function to read variable length blocks of data from file while open
  • apply a javascript function to draggable copy
  • Aptana 3 remove bundle (jquery)
  • netsh acl setting (need alternative method - registry settings?)
  • Primefaces :radioButton inside a ui:repeat
  • R convert summary result (statistics with all dataframe columns) into dataframe
  • Breaking out column by groups in Pandas
  • Unable to get column index with table.getColumn method using custom table Model
  • preg_replace Double Spaces to tab (\\t) at the beginning of a line
  • Xamarin Forms - UWP Fonts
  • Fetching methods from BroadcastReceiver to update UI
  • C# - Serializing and deserializing static member
  • Problems to linebreak with an int in JLabel
  • Date difference with leap year
  • How would I use PHP exceptions to define a redirect?
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Join two tables and save into third-sql
  • JSON with duplicate key names losing information when parsed
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Updated Ionic CLI but shows previous version (Windows)
  • Display Images one by one with next and previous functionality
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Matplotlib draw Spline from multiple points
  • XCode can't find symbols for a specific iOS library/framework project
  • Calling of Constructors in a Java
  • Compare two NSDates in iPhone
  • Arrays break string types in Julia
  • Transpose CSV data with awk (pivot transformation)
  • Use group_by to filter specific cases while keeping NAs
  • log4net write single file for each call to log.info
  • Benchmarking RAM performance - UWP and C#
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal