Borrar filtros
Borrar filtros

matrix manipulation

2 visualizaciones (últimos 30 días)
eri
eri el 1 de Feb. de 2012
Editada: Jan el 27 de Sept. de 2013
how to take matrix element (i.e row) one by one and save each new matrices in a new variable example:
original matrix: a=[2 6 7 8;4 5 3 7;9 7 6 9;5 3 1 9]
become: a1=[4 5 3 7;9 7 6 9;5 3 1 9] a2=[2 6 7 8;9 7 6 9;5 3 1 9] a3=[2 6 7 8;4 5 3 7;5 3 1 9] a4=[2 6 7 8;4 5 3 7;9 7 6 9]

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 2 de Feb. de 2012
a=[2 6 7 8;4 5 3 7;9 7 6 9;5 3 1 9]
id = ~eye(size(a));
h = arrayfun(@(i1)a(id(:,i1),:),1:size(id,2),'un',0);
[out,idxout] = min(cellfun(@(x)det(x*x.'),h))
OR
a=[2 6 7 8;4 5 3 7;9 7 6 9;5 3 1 9]
id = ~eye(size(a));
s = size(a,2);
h = zeros(s*[1 1 1] - [1 0 0]);
kt = zeros(s,1);
for j1 = 1:s
k = a(id(:,j1),:);
kt(j1) = det(k*k.');
h(:,:,j1) = k;
end
[out,outidx] = min(kt)
  5 comentarios
eri
eri el 2 de Feb. de 2012
@andrei bobrov
your second code seem to work fine, could you explain how it works?
@andrei bobrov and Walter Roberson
i am using matlab 7
eri
eri el 3 de Feb. de 2012
@andrei bobrov
can you explain your code, since i need to actually work with larger matrix and more complicated function
i don't understand from line 4 onwards

Iniciar sesión para comentar.

Más respuestas (2)

Sean de Wolski
Sean de Wolski el 1 de Feb. de 2012
Don't do it. That is all.
If you explain your end goal to us we can help you find a better way.
  4 comentarios
eri
eri el 1 de Feb. de 2012
@Jan Simon
and how is that?
Walter Roberson
Walter Roberson el 2 de Feb. de 2012
Use cell arrays, as described in that FAQ entry.

Iniciar sesión para comentar.


eri
eri el 2 de Feb. de 2012
can someone help me?
  1 comentario
Sean de Wolski
Sean de Wolski el 2 de Feb. de 2012
What does:
which -all arrayfun
return? And what is the output from:
ver
at the command line?

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by