how to equlaize cell arrays in matlab?

1 visualizzazione (ultimi 30 giorni)
Jwana
Jwana il 30 Ott 2012
Hi,
I have a cellarray with length of 3 and I want to make for loop with another cell array with length of 6 , so how can I add extra 3 cells for the first array inorder to make the 2 cell arrays equal and to use my for loop in matlab??

Risposta accettata

Pedro Villena
Pedro Villena il 30 Ott 2012
Modificato: Pedro Villena il 30 Ott 2012
A = [A cell(size(A))]; %%to duplicate a row array
A = [A; cell(size(A))]; %%to duplicate a column array
A = [A cell(1,3)]; %%to add 3 columns
A = [A; cell(3,1)]; %%to add 3 rows
  1 Commento
Jwana
Jwana il 30 Ott 2012
thank you for your respond... actually I need the code for a general case not only for a case of 6 and 3 cell array... the following is an example of my code ( not the real code because it is too much complicated ):
type= { '12' '62' '5' };
colour={'re' 'green' 'yellow' 'brown' 'blue' 'black'};
for i=1:length(colour)
if isequal(colour(i),type(:))
result(i)=type(i);
else
end
end
so I need to make the 'type' cell array with the same size with 'colour' cellarray (I think I have to add extra 3 empty cells 9 which is the difference) in side the 'type' cellarray)

Accedi per commentare.

Più risposte (1)

Pedro Villena
Pedro Villena il 30 Ott 2012
Modificato: Pedro Villena il 30 Ott 2012
type= { '12' '62' '5' };
colour={'red' 'green' 'yellow' 'brown' 'blue' 'black'};
result = type;
for i=length(type)+1:length(colour),
result(i)={'0'};
end
or
result = type;
result(length(type)+1:length(colour)) = {'0'}

Categorie

Scopri di più su Data Type Identification in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by