How can i remove empty cells and print only the nonempty cell in a cell array?
Afficher commentaires plus anciens
I have two cell arrays. Q1 and Q2
My cell array's are like this :
q1 = '+ab' <1x1 cell> '+BD'
q2 = <1x1 cell> '+aC'
My output required :
+ab+BD+aC
Réponses (2)
Andrei Bobrov
le 16 Fév 2014
Modifié(e) : Andrei Bobrov
le 18 Fév 2014
strcat(q1(end),q2(end))
ADD
q1 = {'+ab' {} '+BD'};
q2 = {{} '+aC'};
q = [q1 q2];
out = cat(2,q{:});
out = cat(2,out{:});
or
out = cell2mat([q1{:},q2{:}]);
David Sanchez
le 18 Fév 2014
%%%your cell
q1 = cell(3,1);
q2 = cell(2,1);
q1{1}='+ab';
q1{2} ={};
q1{3}='+BD';
q2{1}={};
q2{2} ='+aC';
code to join the non-empty cells
n=1;
for k=1:numel(q1)
if ~isempty(q1{k})
q3{n} = q1{k};
n=n+1;
end
end
for k=1:numel(q2)
if ~isempty(q2{k})
q3{n} = q2{k};
n=n+1;
end
end
q3 =
'+ab' '+BD' '+aC'
1 commentaire
Andrei Bobrov
le 18 Fév 2014
[q1{:},q2{:}]
Catégories
En savoir plus sur Cell Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!