Cell array....searching without a loop?

3 views (last 30 days)
jenka
jenka on 10 Nov 2012
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 Comments
jenka
jenka on 10 Nov 2012
Hi Azzi, I just replied below. Thank you!
Jan
Jan on 10 Nov 2012
Do you mean cat(1, ...)? What should A{:}(i,j,k) do? It is no valid Matlan syntax.

Sign in to comment.

Answers (1)

Matt Fig
Matt Fig on 10 Nov 2012
Edited: Matt Fig on 10 Nov 2012
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)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!