zgyin的个人博客分享 http://blog.sciencenet.cn/u/zgyin

博文

idl程序:可变步长

已有 3994 次阅读 2012-9-30 17:43 |个人分类:idl使用方法|系统分类:科研笔记| 可变步长

2.5     2.6
3.4     3.2
2.7     2.8
5.7     5.8
4.2     4.4
8.1     8.0
1.2     1.3
7.3     7.2
6.6     6.7
9.2     9.3
10.4    10.5
11.3    11.2
12.5    12.3
13.2    13.0
10.2    10.0
14.2    14.1
15.0    14.9
16.6    16.3
17.2    17.1
18.9    19.0
4.7     5.6
5.9     6.1
3.2     5.2
7.3     4.5
19.2    20
19.5    20.5
20.3    18.9
2.3     3.2
4.9     3.4
5.9     6.7
 
两列数,如果横坐标取步长的中间值,纵坐标取步长范围内所有点的平均值,按第一列分组,则第一列为横坐标,按第二列分组,则第二列为横坐标
pro changablestep
st=''
datapath=''
plotpath=''
read,datapath,prompt='请输入数据路径,例如F:data.dat'
read,st,prompt='按第一列分组请输入:one,按第二列分组请输入:two  '
read,step,prompt='请输入步长:'
read,plotpath,prompt='请输入图片存储路径,例如F:image.ps'
print,plotpath
;按第一列分组
if strcmp(st,'one') then begin
READCOL,datapath,F='f,f',col1,col2
endif
;按第二列分组
if strcmp(st,'two') then begin
READCOL,datapath,F='f,f',col2,col1
endif
result1=min(col1)
result2=max(col1)
result3=result2-result1
r1=result3/step
L=round(r1)
if round(r1) ge r1 then begin
L=round(r1)-1
endif
i=0
x=fltarr(L+1)
y=fltarr(L+1)
while i le L do begin
step1=result1+i*step
step2=result1+(i+1)*step
x[i]=(step2+step1)/2.0
ave=0.0
m=0
k=0
n=n_elements(col1)-1
while k le n do begin
if col1[k] ge step1 and col1[k] lt step2 then begin
m=m+1
ave=ave+col2[k]
endif
k++
endwhile
if m eq 0 then begin
y[i]=ave/(m+1)
endif
if m ne 0 then begin
y[i]=ave/m
endif
i++
endwhile
n1=0
i=0
while i le L do begin
if y[i] ne 0.0 then begin
n1++
endif
i++
endwhile
x1=fltarr(n1)
y1=fltarr(n1)
help,x1
n2=0
i=0
while i le L do begin
if y[i] ne 0.0 then begin
x1[n2]=x[i]
y1[n2]=y[i]
n2++
endif
i++
endwhile
print,x1,y1
set_plot,'ps'
device,file=plotpath
coeff=linfit(x1,y1)
yfit=coeff[0]+coeff[1]*x1
plot,x1,y1,psym=2
oplot,x1,yfit
device,/close
end
画出来的图


https://wap.sciencenet.cn/blog-783377-618127.html

上一篇:赤道坐标系和银道坐标系之间的转换方法
下一篇:fits到bur的转换程序
收藏 IP: 202.101.72.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-24 04:48

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部