all submatrices of given order of a given matrix
    4 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I am new in matlab. Is it possible to compute the all submatrices of given order of a given matrix M? For example suppose we have a matrix M of order m by n, and want to compute the all submatrices of order k by n, for some k <= m.
thanks
1 件のコメント
  John D'Errico
      
      
 2015 年 1 月 8 日
				By the way, expect this to be HUGE for even reasonable values for your matrix sizes.
m = 50;
n = 25;
nchoosek(m,n)
ans =
   1.2641e+14
So there are roughly 126 trillion such sub-matrices. If you will store them too, it will take a serious amount of memory. Just the work to generate them all will be immense, even if done in a loop rather than all at once.
回答 (1 件)
  Guillaume
      
      
 2015 年 1 月 8 日
        Use nchoosek(1:m, k) to find all the possible combination of rows to pick in your matrix, and pick these rows:
%random demo data
m = 5; n = 4;
mx = reshape(1:m*n, m, n);
k = 3;
subrows = num2cell(nchoosek(1:m, k), 2);
subm = cellfun(@(rows) mx(rows, :), subrows, 'UniformOutput', false)
5 件のコメント
  Daniel Wilson-NUnn
 2015 年 8 月 17 日
				Hi Guillaume, I have been looking at this answer, and I would like to be able to use this code to select all 2x2 matrices of a bigger nxn matrix. Would you be able to advise as to how to do this?
Many thanks
  Guillaume
      
      
 2015 年 8 月 17 日
				Daniel, please start a new question. You'll get more people to contribute that way
参考
カテゴリ
				Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


