Using arrayfun on the indices of a cell array to calculate all cells in one call?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have two cell arrays. One called Xcell which is of size 25x9 where each cell element is a design matrix for example of size 3600x664, but it can vary from row to row of the cell array (but always the same along the columns).
The second cell array, Ycell, is of size 1x9 where each cell element is the response variable to the Xcell elements.
I want to solve all the X\Y systems as quick as possible. First I define a function to solve each Xcell by using its corresponding Ycell like this:
myfun = @(sample,folds) Xcell{sample,folds}\Ycell{1,folds};
and if I now for example want to solve Xcell{3,2} with its corresponding Ycell{1,2} I can call the function:
a = myfun(3,2);
And everything works fantastic. However, my next step is to try and do this for all of the indices in the cell array using arrayfun.
But when I write it like this:
a = arrayfun(@(sample,folds) myfun(sample,folds),1:25,1:9,'UniformOutput',0);
I get:
Error using arrayfun
All of the input arguments must be of the same size and shape.
Previous inputs had size 25 in dimension 2. Input #3 has size 9
Could someone who understands arrayfun better than I do please explain what I’m doing wrong and how I should write it to do what I want? Thanks!
댓글 수: 0
답변 (1개)
Azzi Abdelmalek
2016년 4월 15일
It's better to use a for loop
댓글 수: 3
Azzi Abdelmalek
2016년 4월 15일
Ok, then post an example, not necessary matrices of sizes 3600x664. Just a small example
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!