필터 지우기
필터 지우기

matrix, using variables like a1,a2,a3,...an, minimum

조회 수: 2 (최근 30일)
eri
eri 2012년 2월 17일
편집: Michael 2013년 10월 15일
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]
then i want to find determinant from each of them * their transpose (ie: det(a1*a1')) and then find which one of them has minimum value
i have asked before and i receive this answer
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)
the problem is i don't know how this code works, and since the matrix i am going to use is different than that i use as example, i can't adjust that code

답변 (3개)

Walter Roberson
Walter Roberson 2012년 2월 17일
  댓글 수: 1
eri
eri 2012년 2월 17일
yes i already read it, but i still don't get it

댓글을 달려면 로그인하십시오.


N/A
N/A 2012년 2월 17일
eval( sprintf( 'a%d=a(%d, :), ', [1;1]*(1:size(a,1))) )

carmen
carmen 2012년 2월 17일
ok heres a brute force version without fancy commands.
a=[2 6 7 8;4 5 3 7;9 7 6 9;5 3 1 9]
rows=size(a,1);
columns=size(a,2);
for i=1:rows
b=1:rows;
b(i)=[];
tmp=a([b],:)
eval(sprintf('a%d=tmp;',i));
determinante(i)=det(tmp*tmp');
end
min=find(determinante==min(determinante)); %gives you the index of
% determinante where the minimum values is found
i hope this works for arbitrary n*m matrices
  댓글 수: 1
carmen
carmen 2012년 2월 17일
add a
determinante(min)
to see what the minimum value is

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by