[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
xyz triplet array to a "flat" 2D array?
- Subject: xyz triplet array to a "flat" 2D array?
- From: "Todd Bowers" <tbowers(at)nrlssc.navy.mil>
- Date: Fri, 21 Jan 2000 11:45:17 -0600
- Newsgroups: comp.lang.idl-pvwave
- Organization: Naval Research Laboratory, Washington, DC
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:18105
Does anybody have a quickie that'll convert data in xyz triplets
to "flat" format? e.g.
x y z to 89.5 89.6 89.7 89.8
89.7 20.1 00.1 20.1 00.1
89.6 20.3 00.2 20.2 00.3
89.8 20.2 00.3 20.3 00.4 00.2
89.5 20.3 00.4
with x running across the top and y down the first column, blanks
are NaN's or whatever. Like it's been interpolated, but without
the interpolation ;).
I've come close, but no cuban. Here's what I was playing around
with last night. I gave up cause I just don't see it.
Thanks alot all
;///////////////
function colsToFlat, dataInCols
xData = dataInCols[0,*]
yData = dataInCols[1,*]
zData = dataInCols[2,*]
sortedXData = xData[sort(xData)]
sortedYData = yData[sort(yData)]
sortedUniqXData = xData[uniq(xData,sort(xData))]
sortedUniqYData = yData[uniq(yData,sort(yData))]
xSortOrder = sort(xData)
ySortOrder = sort(yData)
numDataPtsInX = n_elements(uniq(xData,sort(xData)))
numDataPtsInY = n_elements(uniq(yData,sort(yData)))
xFlat = sortedXData ;sortedUniqXData
yFlat = sortedYData ;sortedUniqYData
zFlat = fltarr(n_elements(xFlat), n_elements(yFlat))
zFlat[xSortOrder,ySortOrder] = zData[*]
; +1 in next line to make room for x row and y column. dataFlat[0,0] just
; unused
dataFlat = fltarr((n_elements(xFlat)+1), (n_elements(yFlat)+1))
dataFlat[*] = !Values.F_NaN
dataFlat[1:*,0] = xFlat
dataFlat[0,1:*] = yFlat
dataFlat[1:*,1:*] = zFlat
;//Need to remove duplicate x and/or y entries
return, dataFlat
end
;///////////////