indexing cellarrays of varying lengths in a cellarray
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Good Day!
Following Problem:
> Given:
% CellArray caCA of N CellArrays CAi of varying sizes >= I
caCA = {CA1, ... CAN};
> Wanted per most efficient way imaginable:
% CellArray of N elements CAi{I}
n_caCA = {CA1{I}, ... CAN{I}};
> Thoughts:
n_caCa = cellfun(@(c) c{I}, caCa);
I'd rather slice my way through this problem, though I'm not sure if it's possible...
2 Commenti
Guillaume
il 16 Ago 2019
You seem to have answered your own question, so I'm not sure what you're asking.
Of course, this will only work for I <= min(cellfun(@numel, caCA))
Risposta accettata
Guillaume
il 16 Ago 2019
Are ther more performant ways to do so?
A loop may be slightly faster as it doesn't have the overhead of the anonymous function call:
n_caCA = zeros(size(caCA));
for idx = 1:numel(caCA)
n_caCA(idx) = caCA{idx}(I);
end
actual performance gain to be tested.
Is it possible to use Matlabs slicing syntax to do so?
No, the matrices in each cell of the cell array may not be stored contiguously in memory, which would be a requirement for slicing. The only way you could perform slicing is by converting the cell array into a matrix, which obviously can't be done if the matrices in the cells are different sizes. Unless of course, you crop the larger matrices to the size of the smallest, but then you'll first have to spend time cropping the matrices.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!