function WCOMBINE, A ;+ ;NAME: ; WCOMBINE ; ;PURPOSE: ; To combine all elements in a matrix, like Matlab's "(:)". ; ;CATEGORY: ; Simple math. ; ;CALLING SEQUENCE: ; Result = WCOMBINE(A) ; ;INPUTS: ; A: A matrix ; ;OUTPUTS: ; The matrix turned into a column with all elements combined. ; ;SIDE EFFECTS: ; If A is an array, it is left unchanged. ; ;RESTRICTIONS: ; None. ; ;EXAMPLE: ; IDL>p = [[2,3],[4,5],[6,7]] ; IDL>print, p ; 2 3 ; 4 5 ; 6 7 ; IDL>print, WCOMBINE(p) ; 2 ; 4 ; 6 ; 3 ; 5 ; 7 ; ;MODIFICATION HISTORY: ; copyright (c) Amara Graps 1995, 1996. ;- t = SIZE(A) IF t(0) eq 1 THEN BEGIN combine = FLTARR(1,N_ELEMENTS(A)) combine(0,*) = A(*) ;1D column array ENDIF ELSE BEGIN numcol = t(1) ;number of columns numrow=t(2) ;number of rows nelems = numcol*numrow ;total number of elements ;Set up array corresponding to type CASE t(3) OF ;column vector containing all elements 1: combine=BYTARR(1,nelems) ;byte 2: combine=INTARR(1,nelems) ;integer 3: combine=LONARR(1,nelems) ;long integer 4: combine=FLTARR(1,nelems) ;float 5: combine=DBLARR(1,nelems) ;double float ELSE: print, 'Do not know datatype in WCOMBINE.PRO!' ENDCASE ;Step through the columns FOR i = 0, numcol-1 DO BEGIN ;Step through the rows FOR j = 0, numrow-1 DO BEGIN combine(i*numrow+j) = a(i,j) END ;j END ;i ENDELSE RETURN, combine end ;************************************************