concatenation by exchange between two matrices

hi I'm trying to do this operation
c =[0 0 1 1 0 0 1 1 0 0 1 1];
d =[0 1 1 0 0 1 1 0 0 1 1 0];
% I need x to be the general concatenation by exchange of
% [c(i) d(i)]....(whatever lengths differ)
%x=[0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 ];
any help

 Accepted Answer

c =[0 0 1 1 0 0 1 1 0 0 1 1];
d =[0 1 1 0 0 1 1 0 0 1 1 0];
n=numel(c)
m=numel(d)
if n>m
d(end+1:n)=nan
elseif n<m
c(end+1:m)=nan
end
x=[c; d]
x=x(:)'
x(isnan(x))=[]

More Answers (2)

Do you mean
x=[c d]
If not, tell what is th expected output
Asmaa El Gharby
Asmaa El Gharby on 28 Feb 2013
Edited: Asmaa El Gharby on 28 Feb 2013
thanks alot @Azzi Abdelmalek it could be also x = [c;d]; x = x(:).';

Categories

Community Treasure Hunt

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

Start Hunting!