all submatrices of given order of a given matrix
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
John D'Errico
el 8 de En. de 2015
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.
Respuestas (1)
Guillaume
el 8 de En. de 2015
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 comentarios
Daniel Wilson-NUnn
el 17 de Ag. de 2015
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
el 17 de Ag. de 2015
Daniel, please start a new question. You'll get more people to contribute that way
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!