For loop in a cell array
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to convert data in a cell array to a matrix, but the dimensions are mismatched. I've found an anonymous function I can use to pad the arrays with NANs so that the cell2mat fuction will make the conversion. My problem now is applying the function to all the arrays without doing so one by one.
For some background, I have a 1x54 cell array. Cell {1,1} is a 1x8 array. The other 53 cells contain a similar array. The 1x8 array is what I have padded with NANs and converted to a matrix using the following function:
maxSize_mint = max(cellfun(@numel,master_mint{1,1})); %master_mint is the 1x54 cell array
out_mint=cell2mat(cellfun(@(x)cat(1,x,nan(maxSize-numel(x),1)),master_mint{1,1},'UniformOutput',false));
now my problem is trying to loop through the 1x54 array to do this to all cells. So far each way I try to do so gives me a different error.
Help please!
4 commentaires
dpb
le 11 Juil 2018
Again, what is the expected output???
It doesn't make any sense from the description that if the first cell is a numeric vector and "The other 53 cells contain a similar array" there should be any issue whatsoever.
Instead of continuing to post nonworking code to try to debug; I suggest attach a small subset of the data (altho 8*54 isn't very big if that's really all there is) and then describe explicitly what the expected output should be.
Jan
le 12 Juil 2018
@Carling Walsh: We want to help you. Please post a clear description.
- What are the inputs?
master_mint is a {1 x 54} cell
master_mint{1,1} is 1x8 array - of which type?
What are the the other elements?
- What is the wanted output?
A 8 x 54 numerical array padded with NaNs?
A {1 x 54} cell array, where the elements are padded with NaNs?
Please post a short but relevant example. The current descriptions are only useful to understand, that the posted code does not work.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!