Using arrayfun on the indices of a cell array to calculate all cells in one call?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Azzi Abdelmalek
le 15 Avr 2016
It's better to use a for loop
3 commentaires
Azzi Abdelmalek
le 15 Avr 2016
Ok, then post an example, not necessary matrices of sizes 3600x664. Just a small example
Voir également
Catégories
En savoir plus sur Entering Commands dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!