# 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=''
print,plotpath
;按第一列分组
if strcmp(st,'one') then begin
endif
;按第二列分组
if strcmp(st,'two') then begin
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

## 全部精选博文导读

GMT+8, 2023-2-9 00:26