home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / softsys / matlab / 206 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  1.7 KB

  1. Path: sparky!uunet!munnari.oz.au!sgiblab!darwin.sura.net!bogus.sura.net!howland.reston.ans.net!usc!rpi!usenet.coe.montana.edu!news.u.washington.edu!atmos.washington.edu!joeb
  2. From: joeb@atmos.washington.edu (Joe Barsugli)
  3. Newsgroups: comp.soft-sys.matlab
  4. Subject: Re: Combining vectors
  5. Date: 27 Jan 93 01:51:11
  6. Organization: Dept. of Atmospheric Sciences, University of Washington
  7. Lines: 37
  8. Distribution: world
  9. Message-ID: <JOEB.93Jan27015111@eos1.atmos.washington.edu>
  10. References: <1993Jan26.182616.11550@vax.oxford.ac.uk>
  11.     <1k5hf2INNlgs@shelley.u.washington.edu>
  12. NNTP-Posting-Host: eos1.atmos.washington.edu
  13. In-reply-to: phantom@stein2.u.washington.edu's message of 27 Jan 1993 08:34:42 GMT
  14.  
  15. In article <1k5hf2INNlgs@shelley.u.washington.edu>
  16. phantom@stein2.u.washington.edu (The Phantom) writes in response to:
  17.  
  18. >   reese@vax.oxford.ac.uk, who wrote:
  19. >
  20. >   >I want to take two vectors and combine them, e.g.
  21. >   >[ a b c d e]  and [ f g h i j ] 
  22. >   >become  [ a f b g c h d i e j ]
  23. >   >
  24. >
  25. >   say a=[ a b c d e ] and b=[ f g h i j ] -- an easy way to do this would be
  26. >   using ...
  27. >
  28. >   len=length(a);            %assuming length(a), length(b) are equal
  29. >   FOR count=1:len,
  30. >       c((count*2)-1)=a(count);
  31. >       c((count*2)=b(count);
  32. >   END
  33. >
  34. >   that seems to work, anyway. just work with the commands for picking out 
  35. >   certain matrix spots and FOR loops, and you should be able to comprise 
  36. >   something that works both ways.
  37. >
  38. >   mt
  39.  
  40.  
  41. How about a method which avoids the FOR loop:
  42.  
  43. c = [a;b];c = c(:)'  to go from a = [a b c ...] b = [f g h  ...] to 
  44.                      c = [a f b g c h ...]
  45.  
  46. and a = c(1:2:length(c));b = c(2:2:length(c)); to unscramble.
  47.  
  48.  
  49. Joe (joeb@atmos.washington.edu)
  50.  
  51.  
  52.