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]

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 2월 2일

1 개 추천

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

eri
eri 2012년 2월 2일
error:
??? Undefined command/function 'arrayfun'.
Andrei Bobrov
Andrei Bobrov 2012년 2월 2일
release of MATLAB ?
Walter Roberson
Walter Roberson 2012년 2월 2일
Based on the error message style, Eri must be using MATLAB 5, I think.
eri
eri 2012년 2월 2일
@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 2012년 2월 3일
@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

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

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2012년 2월 1일

1 개 추천

Don't do it. That is all.
If you explain your end goal to us we can help you find a better way.

댓글 수: 4

eri
eri 2012년 2월 1일
my goal is to find the product of the result matrices * their transpose, find its determinant, find which one has the smallest determinant, then repeat the process all over again until there is only one row left
Jan
Jan 2012년 2월 1일
@eri: And this is more efficient and more flexible, if you use dynamic indices instead of a copy to a separate variable.
eri
eri 2012년 2월 1일
@Jan Simon
and how is that?
Walter Roberson
Walter Roberson 2012년 2월 2일
Use cell arrays, as described in that FAQ entry.

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

eri
eri 2012년 2월 2일

0 개 추천

can someone help me?

댓글 수: 1

Sean de Wolski
Sean de Wolski 2012년 2월 2일
What does:
which -all arrayfun
return? And what is the output from:
ver
at the command line?

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

카테고리

도움말 센터File Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

질문:

eri
2012년 2월 1일

편집:

Jan
2013년 9월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by