필터 지우기
필터 지우기

Retrieving Arrays

조회 수: 1 (최근 30일)
RDG
RDG 2011년 10월 29일
Suppose I have 4 cell arrays with 4 matrices in each cell array;
A{1}=[1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4; 4 8 12 16]
A{2}=[2 3 4 5; 2 3 4 5; 2 3 4 5; 2 3 4 5; 8 12 16 25]
A{3}=[3 4 5 6; 3 4 5 6; 3 4 5 6; 3 4 5 6; 12 16 25 24]
A{4}=[4 5 6 7; 4 5 6 7; 4 5 6 7; 4 5 6 7; 16 20 24 28]
I would like to retrieve 2 (of the best) cells according to the content of the matrices in [5,4] (notice that they're the summation of the elements above them). Let's just say I want to retrieve the matrices whose value of the [5,4] is closer to 0, it means that I will have A{1} and A{2} as my result.
May I know how to get about this?
  댓글 수: 2
Fangjun Jiang
Fangjun Jiang 2011년 10월 29일
Is the matrix in each cell always the same size? The last element of A{2} should be 20. It shouldn't matter but your expect result will be different.
RDG
RDG 2011년 11월 3일
It's my mistake. It doesn't really affect my result. Thanks.

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

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 10월 29일
A{1}=[1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4; 4 8 12 16];
A{2}=[2 3 4 5; 2 3 4 5; 2 3 4 5; 2 3 4 5; 8 12 16 25];
A{3}=[3 4 5 6; 3 4 5 6; 3 4 5 6; 3 4 5 6; 12 16 25 24];
A{4}=[4 5 6 7; 4 5 6 7; 4 5 6 7; 4 5 6 7; 16 20 24 28];
B=cell2mat(A);
[m,n]=size(A{1});
b=B(m,n*(1:n));
[b,ind]=sort(abs(b));
ind=ind(1:2);
SelectA=A(ind);
celldisp(SelectA);
  댓글 수: 3
Andrei Bobrov
Andrei Bobrov 2011년 10월 29일
[ign,i1] = sort(cellfun(@(x)x(numel(x)),A))
out=A(i1(1:2))
RDG
RDG 2011년 10월 29일
Splendid!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by