http://www.mathworks.com/matlabcentral/newsreader/view_thread/325314
MATLAB Central Newsreader  doubts in matlab for combining two vectors
Feed for thread: doubts in matlab for combining two vectors
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Thu, 20 Dec 2012 06:17:17 +0000
doubts in matlab for combining two vectors
http://www.mathworks.com/matlabcentral/newsreader/view_thread/325314#894020
Shobana
hai friends..<br>
<br>
I want to merge two vectors like in the below specified manner<br>
for example:<br>
a= [1 , 2....n1]; b = [3 , 4.......n2]<br>
then 'c' should be like this c = [1 3 2 4 .........n1,n2]<br>
i tried like this c = [a,b] but this is not working<br>
here the value of n1 and n2 will be known at the run time only.

Thu, 20 Dec 2012 07:12:21 +0000
Re: doubts in matlab for combining two vectors
http://www.mathworks.com/matlabcentral/newsreader/view_thread/325314#894027
Roger Stafford
"Shobana " <manoharanshobana@ymail.com> wrote in message <kauahd$qj5$1@newscl01ah.mathworks.com>...<br>
> I want to merge two vectors like in the below specified manner<br>
> for example:<br>
> a= [1 , 2....n1]; b = [3 , 4.......n2]<br>
> then 'c' should be like this c = [1 3 2 4 .........n1,n2]<br>
          <br>
Assuming that a and b are row vectors of possibly differing lengths, we append the excess of either at the right end:<br>
<br>
n = min(size(a,2),size(b,2));<br>
c = [reshape([a(1:n);b(1:n)],1,[]),a(n+1:end),b(n+1:end)];<br>
<br>
Roger Stafford

Thu, 20 Dec 2012 07:13:22 +0000
Re: doubts in matlab for combining two vectors
http://www.mathworks.com/matlabcentral/newsreader/view_thread/325314#894028
Nasser M. Abbasi
On 12/20/2012 12:17 AM, Shobana wrote:<br>
> hai friends..<br>
><br>
> I want to merge two vectors like in the below specified manner<br>
> for example:<br>
> a= [1 , 2....n1]; b = [3 , 4.......n2]<br>
> then 'c' should be like this c = [1 3 2 4 .........n1,n2]<br>
> i tried like this c = [a,b] but this is not working<br>
> here the value of n1 and n2 will be known at the run time only.<br>
><br>
<br>
may be:<br>
<br>
<br>
N = 4;<br>
A = [1 2 3 4];<br>
B = [3 4 5 6];<br>
C = zeros(1,2*N);<br>
<br>
C(1:2:2*N1) = A;<br>
C(2:2:2*N) = B<br>
<br>
<br>
C =<br>
1 3 2 4 3 5 4 6