How can I fill a cell array?

17 visualizzazioni (ultimi 30 giorni)
Pamela
Pamela il 31 Ott 2012
Hi,
To create a cell array with 3 cells should I do this?
B = cell(3,2);
To fill this cell array with values from c according to the values in A knowing that c and A are a vectors. should I do this?
number=length(A);
for i=1:number
if (A<0)
B{1} = [B{1} c];
elseif (0<=A<=7)
B{2} = [B{2} c];
elseif (7<A<=10)
B{3} = [B{3} c];
end
end
thanks

Risposta accettata

Matt J
Matt J il 31 Ott 2012
Modificato: Matt J il 31 Ott 2012
Here's a different approach,
B=cell(3,1);
f=@(m) repmat(c,1,nnz(m));
B{1}=f(A<0);
B{2}=f(A>=0 & A<=7);
B{3}=f(A>7 & A<=10);
  5 Commenti
Matt J
Matt J il 1 Nov 2012
B{1}=c(A<0);
B{2}=c(A>=0 & A<=7);
B{3}=c(A>7 & A<=10);
Pamela
Pamela il 1 Nov 2012
thank you

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Operators and Elementary Operations 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!

Translated by