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

 采纳的回答

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))=[]

更多回答(2 个)

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

类别

在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by