how to make all vectors to equal size for a cell array.

1 vue (au cours des 30 derniers jours)
Sandhu
Sandhu le 10 Oct 2011
Modifié(e) : per isakson le 1 Déc 2017
hi, i have a cell array of z{k}, it has totally 60 cells. which are diffident size in columns. so while i am trying to plot all arrays data in a single plot,[plot(z{1}) it works for one cell.] it says all vectors must have same size.
plot(z{:})
??? Error using ==> plot
Vectors must be the same lengths.
so, i want to make equal size of vectors by placing zeros. so any one can please help me.

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 10 Oct 2011
It might be easier using a for-loop, with hold on;
figure;hold on;
for k=1:length(z)
plot(z{k});
end
  1 commentaire
Sandhu
Sandhu le 10 Oct 2011
tnq very much for ur help..it works grate.

Connectez-vous pour commenter.

Plus de réponses (1)

Laura Proctor
Laura Proctor le 10 Oct 2011
lv = max(cellfun(@length,z));
za = zeros(1,lv);
for idx = 1:length(z)
cellVal = z{idx};
if length(cellVal) < lv
z{idx} = za;
z{idx}(1:length(cellVal)) = cellVal;
end
end
  2 commentaires
Sandhu
Sandhu le 10 Oct 2011
tnq very much for help. it also works. tnx alot.
Mansour Aljohani
Mansour Aljohani le 20 Août 2015
Thank you so much Laura

Connectez-vous pour commenter.

Catégories

En savoir plus sur Operators and Elementary Operations 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