ndgrid on matrices without the use of cell arrays

4 visualizaciones (últimos 30 días)
jack
jack el 23 de Dic. de 2015
Comentada: jack el 24 de Dic. de 2015
Hi guys,
I need your help in solving the following problem:
Given a dxn matrix, do the following (preferably without the use of cells):
n is always even and d is also even.
Thanks in advance.
  2 comentarios
James Tursa
James Tursa el 23 de Dic. de 2015
Editada: James Tursa el 23 de Dic. de 2015
What is the general pattern? E.g., are the rows always split into 1x2 blocks, or are the rows split in half? Is n always even? You need to give us more information.
jack
jack el 23 de Dic. de 2015
Editada: jack el 23 de Dic. de 2015
I have updated the question.
The aim is very similar to the problem stated by the following link: http://www.mathworks.com/matlabcentral/answers/258365-ndgrid-on-cell-array-of-vectors
but i need your help in solving it for matrices.

Iniciar sesión para comentar.

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 23 de Dic. de 2015
Editada: Andrei Bobrov el 23 de Dic. de 2015
m = size(A,1); % A - your array
b = reshape(A,m,[],2);
[ii,jj] = ndgrid(1:m);
out2 = [b(jj(:),:,1),b(ii(:),:,2)]
  2 comentarios
jack
jack el 24 de Dic. de 2015
Editada: jack el 24 de Dic. de 2015
Your suggestion is good but it is not fully correct, to correct it change only b to :
b = reshape(A,m,[],size(A,2)/2);
and making the output of ndgrid a cell array.
jack
jack el 24 de Dic. de 2015
but how can i do it without cell arrays? i need a code that works for every even n and d = 2!!

Iniciar sesión para comentar.

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!

Translated by