Cell array....searching without a loop?

2 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by