loop-free numeric array indexing when numeric array inside cell array
조회 수: 12 (최근 30일)
이전 댓글 표시
My objective is to apply a given function "myfun" to each column within a cell array, using an index vector. I provide an example to be more clear:
C = cell of size(C) = [M, 1];
Each row of C contains an array of the same size. I will call the "k_th" array A_k so that C{k,1} = A_k.
ind = a cell array the same size as C, containing integers.
icol = an array of integer shift values where size(icol) = [size(A_k,2), 1];
Goal: Shift a certain columns ind{k}, in each A_k contained within C by an amount specified by vector icol( : , ind{k} ) WITHOUT the following loop:
for k = 1:size(C,1),
this{k} = circshift( C{ k , 1}, icol( : , ind{k} ) );
end;
I often use "cellfun" or "arrayfun" to operate on arrays, but this seems harder. Thank you in advance.
댓글 수: 0
채택된 답변
Geoff
2012년 3월 15일
You can use cellfun for this if you combine the C and ind cell arrays: ie chuck the ind array as a new column in C.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!