home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.soft-sys.matlab
- Path: sparky!uunet!charon.amdahl.com!amdahl!rtech!sgiblab!darwin.sura.net!bogus.sura.net!howland.reston.ans.net!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!mmm.serc.3m.com!pwcs!medtron!norway!jw7348
- From: jw7348@norway.medtronic.com (Jeff Wilkinson)
- Subject: Re: Combining vectors
- Message-ID: <1993Jan27.213533.12837@medtron.medtronic.com>
- Sender: news@medtron.medtronic.com (USENET News Administration)
- Nntp-Posting-Host: norway.inst.medtronic.com
- Organization: Medtronic, Inc., Minneapolis, MN
- References: <1993Jan26.182616.11550@vax.oxford.ac.uk>
- Date: Wed, 27 Jan 1993 21:35:33 GMT
- Lines: 49
-
- In article <1993Jan26.182616.11550@vax.oxford.ac.uk> reese@vax.oxford.ac.uk writes:
- >
- >
- >I want to take two vectors and combine them, e.g.
- >[ a b c d e] and [ f g h i j ]
- >become [ a f b g c h d i e j ]
- >
- >Does anyone know a quick and easy way to do this, and the reverse of
- >it? Thanks in advance for your help!
- >
- >Jason
-
-
- Jason,
-
- Try this for 2 equal length input vectors:
-
- >> v1 = [1 2 3]; % create a vector for each
- >> v2 = [4 5 6]; % operand
- >> inx = 1:length([v1,v2]); % create an indexing vector equal
- >> inx = rem(inx,2); % to the summed length
- >> result = zeros(size(inx)); % allocate the result vector
- >> result(inx) = v1; % put the v1 at odd indices
- >> result(~inx) = v2; % fill in the even with v2
- >> result
-
- result =
- 1 4 2 5 3 6
-
- >> result(inx) % retrieve v1
-
- result =
-
- 1 2 3
-
- >> result(~inx) % retrieve v2
-
- result =
-
- 4 5 6
-
-
- Hope this helps,
-
- ------------------------------------------------------------------------
- Jeff Wilkinson Internet: wilk@medtronic.com
- Medtronic, Inc. Voice +1-612-574-3770
- 7000 Central Ave NE FAX +1-612-574-4306
- Minneapolis, MN 55432
-