X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 12 May 2006 03:27 PM by  anon
dividing arrays of different sizes within a for loop
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
12 May 2006 03:27 PM
    The code below is a diluted version of the one that I am working on. Basically i would like to divide each element of a 40 element floating array by n. n refers 512 single arrays. I would like all this done within a for loop of 0, 511 so that the 40 element array would be divided by one n per increment in the loop. In the end I would like each of the 512 40 element arrays to be plotted against 512 arrays of 40 elements each. However I seemed to be stuck.....any ideas? thanks terry ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; pro cal image=mrdfits('/home/terry/jtse2-1.fts') gen=indgen(131) tb= gen[90:130] * (0.048/210.) XX=ATAN(tb) ;angle at every point ; 512 fltarr of 41 elements help,COS(XX) x0=346.5 y0=38. x2=511. for y2=0,512 do begin prof_right=profile_ni(image,[[x0,y0],[x2,y2]]);generates multiple profiles of image max_dist=lclxtrem(prof_right[90:130],40,/MAXIMA);finds the maximum of each profile and returns position along profile max_dist=max_dist+90 ;find the distance of the maximum point from 90 fringe_1=prof_right[90:130] mf1=max(fringe_1)-fringe_1 ; find the maximum value of each profile and subtract all other values from this max. ;print,y2,mf1 ;ta=Tan (A) ta = max_dist * (0.048/210.) A=ATAN(ta);angle at maxima;512 fltarrs of 1 element each n = (2.*296.*COS(A))/(0.5303) ; 512 single arrays ;print,y2,n ll=(2.*296.*COS(XX)) ; 512 identical arrays of 40 elements each print,ll,y2 ll=ll/n ; I would like to divide each 40 element of each array ll by n with +1 increments in n. ;ll comes out as an array of 1 element! llo=(2.*296.*COS(A))/(n) wavelength=(ll-llo)*10000 ; microns to angstroms ; should be 512 arrays of 40 elements each ;print,wavelength,mf1 ;eventually want all 512 plots of wavelength vs mf1 endfor end

    Deleted User



    New Member


    Posts:
    New Member


    --
    12 May 2006 03:27 PM
    Terry, I can probably come up with an idea, but all the math functions of your code are getting in the way of my understanding what you are asking. If you could give a simple example scenario, providing the name, the dimensions and the data type of the arrays that would represent the inputs, what math these different inputs are performing on one another, and, finally, the name, the dimensions and the data typr of the output arrays, then I think I could provide you with an optimal or near-optimal solution. And this optimal solution probably does not require much loop processing in the IDL language. For example, let's say your general scenario is: 'x' is a 40-element vector. 'y' is a 512 column by 40 row array of numbers. Each column in 'y' represents the array that each element of 'x' should be divided by. The output 'result' should be a 512 x 40 array, where result[i, j] = x[j] / y[i,j]. In this scenario, a logical IDL approach would be: ; 'result' is going to be 512 columns of the 'x' vector divided by a vector subset ; from 'y', so start by setting 'result' equal to 512 copies of the 'x' vector. result = x # ( fltarr(512) + 1 ) ; Matrix math will produce the intermediate 512 x 40 array result = temporary(result) / y ; TEMPORARY just used to save memory Is this the division scenario you were trying to describe? James Jones
    You are not authorized to post a reply.