# Equalizing the size of arrays in a cell

6 vues (au cours des 30 derniers jours)
Lui le 18 Juil 2020
Commenté : madhan ravi le 18 Juil 2020
Hi everyone,
I have 300 sets of data held in a 1 by 300 cell. The data is of unequal length and as such, it is difficult to change the cell to an array as I would love to. Instead, I would like to make the size of the arrays to be uniform for that to work. The array dimensions should be (1000 by 1) but some of the arrays have 400, 230 etc. I would therefore like to fill the arrays with zeros for the parts that there is no entry to make them have a length of 1000. Is there anyone with an idea?
I have looked at this solution but it does not seem to work for my case. How can I adapt the same?
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Sugar Daddy le 18 Juil 2020
Modifié(e) : Sugar Daddy le 18 Juil 2020
Suppose my variable name is y
if data is row vector
z = cellfun(@(x) [x zeros(1,100-length(x))],y,'uni',0);
if data is column vector
z = cellfun(@(x) [x;zeros(100-length(x),1)],x,'uni',0);
##### 2 commentairesAfficher AucuneMasquer Aucune
Lui le 18 Juil 2020
Thank you so much.
Lui le 18 Juil 2020
Worked !!

Connectez-vous pour commenter.

### Plus de réponses (1)

Lui le 18 Juil 2020
I worked out a different solution though.
for N=300 % entries in the cell
Y{1,N}(numel(Y{1,1}))=0 % where Y{1,1} has the desired length.
end
I appreciate the contribution.
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
madhan ravi le 18 Juil 2020
XD

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Creating and Concatenating Matrices 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!

Translated by