经常在IDL中遇到需要从大的二维数组中需要提取小的二维数组的情况。这里用矩阵乘法写了一个函数,可以实现从大的数组中提取子数组。这个函数返回的是要提取的数组的下标。
;从大的二维数组中提取一块区域
; r 原数组的行数
; c 原数组的列数
; ro 子数组在原数组中的起始行号
; co 子数组在原数组中的起始列号
; rs 子数组的行数
; cs 了数组的列数
function getIndex, r, c, ro, co, rs, cs
rb = lindgen(cs, start=1,increment=0) # lindgen(rs, start=0, increment=c)
cb = lindgen(cs, increment=1) # indgen(rs, start=1,increment=0)
return, rb + cb + long(ro) * c + co
end
调用示例如下:
pro test
r = 13
c = 11
dat = indgen(c,r)
ro = 1
co = 1
rs = 7
cs = 5
index = getIndex(r, c, ro, co, rs, cs)
;print,pos
pr
IDL中高效子数组提取

最低0.47元/天 解锁文章
1177

被折叠的 条评论
为什么被折叠?



