Cell array....searching without a loop?

조회 수: 1 (최근 30일)
jenka
jenka 2012년 11월 10일
I have a cell array A. Size is 200x1. The size of A{1} is 501x201x119=i x j x k. The same is true for other cells in A. Now for each point in dimension i that goes from 1 to 501, I need to extract appropriate point from each cell, and find 90 percentile of these points and save it into 501x201x119 array. Could you please help if you have elegant solution to this problem.
EDITED By Matt Fig to add (from an 'Answer' by jenka):
Let me make it more clear. Let's say, per Matt, suggestion
A = {rand(5,3,2);rand(5,3,2);rand(5,3,2);rand(5,3,2)};
Sorry I do not have a excess to matlab right now so this is pseudo code:
for j=1:3
for k=1:2
B = [];
for i=1:5
B = cat(A{:}(i,j,k), B, 1); %not sure if we can do something like this
end
per_90_mat(i,j,k) = prcntile(B,90);
end
end
  댓글 수: 4
jenka
jenka 2012년 11월 10일
Hi Azzi, I just replied below. Thank you!
Jan
Jan 2012년 11월 10일
Do you mean cat(1, ...)? What should A{:}(i,j,k) do? It is no valid Matlan syntax.

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

답변 (1개)

Matt Fig
Matt Fig 2012년 11월 10일
편집: Matt Fig 2012년 11월 10일
Post a simple, small example of the FOR loop you have been using to solve the problem. Say
A = {rand(5,3,2);rand(5,3,2);rand(5,3,2);rand(5,3,2)};
Now what are you doing with A?
EDIT
O.k., so it looks like you want to do something like this without the loops:
I = 5;
J = 3;
K = 2;
A = {randi(10,I,J,K);randi(10,I,J,K);randi(10,I,J,K)};
for jj=1:J
for kk=1:K
for ii=1:I
B = cellfun(@(x) x(ii,jj,kk),A);
per_90_mat(ii,jj,kk) = prctile(B,90);
end
end
end
You can do the same thing like this:
per_90_mat2 = prctile(cat(4,A{:}),90,4)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by