IgorPro实用教程代码.docx
《IgorPro实用教程代码.docx》由会员分享,可在线阅读,更多相关《IgorPro实用教程代码.docx(129页珍藏版)》请在冰豆网上搜索。
![IgorPro实用教程代码.docx](https://file1.bdocx.com/fileroot1/2023-4/19/1aeaa15f-c8ce-46d8-a946-826687af9b38/1aeaa15f-c8ce-46d8-a946-826687af9b381.gif)
IgorPro实用教程代码
IgorPro实用教程代码
第1章
1.1.7
Variablev1,v2
Strings1=”hello”,s2
Make/N=100data1
Print2+sqrt(3)+5A3+6A0.3
Printsin
(1),ln(3),exp
(2)Make/O/N=100data1Setscale/Ix,0,2*pi,data1
Data1=sin(x)
Fftdata1Make/O/N=100data1
Data1=x+gnoise
(1)
Curvefitlinedata1/D
Displaydata1
Editdata1
Displaydata1
ModifyGraphmode(data1)=3,marker(data1)=19
Sin
(1)//error
Printsin
(1)
1.2.1
Make/O/N=100data
Setscale/Ix,0,1,data
Data=x
Editdata//只显示data内容
Editdata.xy//显示data内容和x坐标信息
Make/O/N=200sinx;
Setscale/Ix,0,2*pi,sinx;sinx=sin(x);
Displaysinx;
Make/O/N=200/Ccmpwave;
Make/O/T/N=200twave;
Setdatafolderroot;//设定当前目录
Newdatafoldertmp;//创建一个名为tmp的目录
Make/O/N=200root:
tmp:
cmpwave;setscale/Px,0,2*pi/199,”s”,sinxsetscale/Ix,0,2*pi,”s”,sinx
Duplicate/Ooldwave,newwave;dupplicate/O/R=(x1,x2)oldwave,newwave;dupplicate/O/R=[p1,p2]oldwave,newwave;
Make/Odata={1,2,3}
Make/Odata
Setscale/Px,0,0.001,data
Variabletau=0.01
Data=exp(-x/0.01)
Make/Odata1
Data1=data[p]
1.2.5
Variablev1;//
Variable/Cv1;//
Variable/Gv1;//Stringstr;//
申明一个普通变量
申明一个复数变量申明一个全局变量申明一个字符串变量
1.2.6
Functionfunc()
Stringcurr=getdatafolder
(1)//获取当前目录
Setdataflodermydestfd//mydestfd应该存在,存放了要处理的数据
//somethingtobedone
Setdatafoldercurr//恢复当前目录
End
1.2.11
Integrate1D(UserFunctionName,min_x,max_x[,options[,count]])
Integrate[/DIM=d/METH=m/P/T][typeFlags]yWaveA[/X=xWaveA][/D=destWaveA][,yWaveB[/X=xWaveB][/D=destWaveB][,...]]
第2章
2.1.1
make/N=100/Ogaussfun,lorfun
setscale/Ix,-1,1,gaussfun,lorfun
gaussfun=exp(-x*x/0.01)
lorfun=1/((x*x)+0.04)
make/N=10XY_Y={4,6,8,4,6,7,9,1,4,3}
make/N=10XY_X={3,5,1,4,7,5,8,6,9,2}
Displaygaussfun
//绘制gaussfun曲线
DisplayXY_YvsXY_Xas“mygraph”
//绘制XY曲线并且设定graph标题为mygraph
Display/L=newLeft/B=NewBottomgaussfunas"mygraph"
//以新建自由坐标轴newLeft和NewBottom绘制gaussfun曲线。
Preferences0;
Display/L=newLeft/B=NewBottomgaussfunas"mygraph";
Graph1Style();
Preferences1;
//以新建坐标轴newLeft和NewBottom为坐标轴绘制gaussfun曲线,并采用预定义样式Graph1Style。
2.1.2
AppendToGraph/L=newLeft/B=newBottomlorfun
//向当前graph添加lorfun,坐标轴为newLeft和newBottom
AppendToGraph/W=Graph0lorfun//
向名为“Graph0”的窗口添加lorfun曲线
2.2.2Make/N=50sinx,cosx;
Setscale/Ix,0,2*pi,sinx,cosx;
Sinx=sin(x);
//创建两个wave
//设置两个wave的x坐标为0到2n//设置wavesinx为它的横坐标的正弦
Cosx=cos(x);
Make/N=(50,2)arrowinfo;
Setscale/Ix,0,2*pi,arrowinfo;//
Arrowinfo[][0]=10;
//设置wavecosx为它的横坐标的余弦
//创建Arrowinfo信息wave
设置Arrowinfowave的x坐标为0到2n,代表一圈
//设置所有的箭头长度都是10;
Arrowinfo[][1]=x;
Displaysinxvscosx;
//设置随着角度的增加箭头偏转的方向
//显示sinx,并且以cosx为横坐标
ModifyGrapharrowMarker(sinx)={arrowinfo,1,5,0.5,1}
//设置Marker为Arrow。
这一步可以也可以通过曲线
//外观设置对话框设置箭头marker完成,注意Arrow//Info要选择arrowinfo
Make/N=100datax,datay,dataz
datax=enoise
(2);datay=enoise
(2);dataz=exp(-(dataxA2+datayA2))
Displaydatayvsdatax;ModifyGraphmode=3,marker=8
ModifyGraphzmrkSize(datay)={dataz,*,*,1,10}
2.2.3
make/Odata
setscale/Px0,1,data
data=exp(-x/60)
displaydata
ModifyGraphmanTick(bottom)={0,30,0,0},manMinor(bottom)={3,2}
make/OInverseTemperature={30,20,14.2857,10,5,3.0303,2.22222,1.25}
make/OMobility={0.211521,0.451599,0.612956,0.691259,0.886406,0.893136,0.
921083,1}
DisplayMobilityvsInverseTemperature//绘制曲线,使用默认坐标轴
ModifyGraphmode=3,marker=8
make/N=5/TTickLable={“20”,”30”,”50”,”100”,”400”}//刻度线标签
make/N=5TickPosition
TickPosition=450/str2num(TickLable)
ModifyGraphuserticks(bottom)={TickPosition,TickLable}
2.2.4
make/Ogaussdata
setscale/Ix,-1,1,gaussdata
gaussdata=gauss(x,0,0.2)
displaygaussdata
ModifyGraphzColor(gaussdata)={gaussdata,*,*,Rainbow256,0}
ModifyGraphmode=4,marker=19
ModifyGraphmskip=5
TextBox/C/N=text0/D={2,2,0}/A=MC"\\JC\\Z15\\F'TimesNewRoman'GaussFunction\re\\S(-x\\S2\\M\\Z14\\S/2\\F'symbol's\\F'TimesNewRoman'\\S2\\M\\Z14\\S)
I!
Twice\{K0}is\{K0*2}
\{"TwiceK0is%g,andtodayis%s",2*K0,date()}
{“xvalue=%g”,tagval
(2)}//输出x的大小,每一个参数表示一种预定义类型
tagwa
{“meanvalue=%g”,mean(tagwaveref(),-inf,+inf}//输出引用wave的平均值,
veref返回wave的引用。
2.4.3
make/O/N=(128,128)gaussdata=gauss(x,64,10,y,64,10)
functionxyzcontour()
make/O/N=(100,3)xyzwave
variablei
for(i=0;i<100;i+=1)
xyzwave[i][0]=gnoise
(1)
xyzwave[i][1]=gnoise
(1)
xyzwave[i][2]=gnoise
(1)
endfor
display;appendxyzcontourxyzwave
end
2.4.5
Make/O/N=(200,30)fdfun;
Setscale/Ix,-1,0.2,fdfun;
fdfun=1/(exp(x*1.6*10000/1.38/30)+1);
duplicate/Ofdfun,lorfun1,lorfun2;
lorfun1=0.005/((x+0.1)A2+0.01);
lorfun2=0.008/((x+0.3)A2+0.01);
fdfun=fdfun+lorfun1+lorfun2
newwaterfallfdfun;//绘制waterfall图
Newwaterfall/Host=graphnamewavename
2.4.6
Duplicate/Ofdfunfdcolor;
Fdcolor=y;
ModifyGraphzColor(fdfun)={fdcolor,*,*,Rainbow256,0};
Modifywaterfallangle=45
2.4.7
Make/N=(100,100)gaussfun;
Setscale/Ix,-0.5,0.5,gaussfun;
Gaussfun=exp(-x*x/0.04-y*y/0.04);
2.5.2
make/O/N=(100,100)data
setscale/Ix,-pi,pi,data
setscale/Ix,-pi,pi,data
data=sin(x)*cos(y)
make/O/N=(20,20,3)dsphere
setscale/Ix,0,pi,dspheresetscale/Iy,0,2*pi,dspheredsphere[][][0]=1*sin(x)*cos(y)dsphere[][][1]=1*sin(x)*sin(y)dsphere[][][2]=1*cos(x)
NewGizmo/N=Gizmo0/T="Gizmo0"
ModifyGizmostartRecMacro
AppendToGizmoSurface=root:
dsphere,name=surface0
ModifyGizmoModifyObject=surface0property={surfaceColorType,1}
ModifyGizmoModifyObject=surface0property={fillMode,3}
ModifyGizmoModifyObject=surface0property={srcMode,4}
ModifyGizmoModifyObject=surface0property={frontColor,0.250004,0.996109,0.250004,1}
ModifyGizmoModifyObject=surface0property={backColor,0.996109,0.664073,0,1}
ModifyGizmosetDisplayList=0,object=surface0
ModifyGizmoSETQUATERNION={0.488416,0.302182,0.455614,0.680110}
Make/O/N=(20,3)data=gnoise(5)
data[][2]=2*data[p][0]-3*data[p][1]+data[p][0F2+gnoise(0.05)
make/N=(100,100)/Odata
setscale/Ix,-2,2,data
setscale/Iy,-2,2,data
data=gauss(x,-1,0.5,y,-1,0.5)+gauss(x,-1,0.5,y,1,0.5)
data=data+gauss(x,1,0.5,y,-1,0.5)+gauss(x,1,0.5,y,1,0.5)
3.1.2
Make/O/N=100trialwave;
Setscale/Ix,-1,3,trialwave;
Trialwave=exp(-0.1*x)+gnoise(0.02);
Displaytrialwave;
ModifyGraphmode=3;
functionfitfun(coef,x):
Fitfunc
wavecoef
variablex
end
make/Ocoef={a1,a2,a3,funcfitfitfun,coef,ydata/D
3.1.3
make/OLorFsetscale/Ix,-10,10,LorFsetrandomseed0.5LorF=1/(x*x+1)+gnoise(0.05)displayLorF
ModifyGraphmode=3,marker=8
3.1.5
Make/O/N=(200,200)w2d
ModifyGraphlsize(fit_LorF)=2,rgb(fit_LorF)=(0,0,65280)
3.2.2
Makewf(x)=a*x*x+b*x+cMake/O/N=200trialdata
Setscale/Px,-2,0.02,trialdataSetrandomseed0.5Trialdata=x*x-2*x-1+gnoise(0.2)
Displaytrialdata
ModifyGraphmode=3,marker=8,rgb=(0,0,65280)
3.2.4
Functionf(w,x):
FitFunc
WavewVariablex
End
Functionf(w,x,y):
FitFunc
Wavew
Variablex
Variabley//functionbody
End
3.3.1
CurveFit[flags]fitType,[kwCWave=coefWaveName,]waveName[flagparameters]
CurveFitfitTypewavenameMake/O/N=20trialdataSetscale/Ix,0,10,trialdataSetrandomseed0.5
Trialdata=exp(-4*(x-5F2)
Displaytrialdata
Modifygraphmode=3,marker=8
VariableV_FitOptions=8//controlfittingCurvefitgausstrialdata
EditM_iterates
K0=1;K1=2;K2=3;K3=4
CurveFit/Ggausstrialdata
Make/O/N=200trialdata
Setscale/Ix0,5,trialdata
Setrandomseed0.5
Trialdata=exp(-(x-2)/2)+gnoise(0.1)
Displaytrialdata
Modifygraphmode=3,marker=8Curvefit/TBOX=768exp_Xoffsettrialdata/D
Curvefit/K={2}/TBOX=768exp_Xoffsettrialdata/DSetAxisleft0,4
SetAxisbottom-1,8
Curvefit/X/TBOX=896exp_Xoffsettrialdata/Dmake/O/N=20trialdata
setscale/Ix,0,2,trialdatasetrandomseed0.5trialdata=exp(-x)+gnoise(0.1)displaytrialdata
modifygraphmode=3,marker=8
Curvefit/TBOX=768exptrialdata/D/F={0.95,6,ErrorBar}
Make/O/N=200trialdata
Setscale/Ix,0,2,trialdata
Setrandomseed0.5Trialdata=2*exp(-x)+gnoise(0.3)
Displaytrialdata
Modifygraphmode=3,marker=8
Curvefit/W=0linetrialdata/D/R
3.3.3
Make/O/N=200data1
Setscale/Ix,0,2*pi,data1
Setrandomseed0.5
Data1=2*sin(x)+gnoise(0.2)
Displaydata1
Modifygraphmode=3,marker=8
K1+K2>3
K3/5<2*K1
K1*K1<2。
-1000
1000
0-100
0100
00-10
0010
000-1
0001
K0,K1,K2,K3
1,1,0,3,0,2,1,1
EditM_FitConstraint,W_FitConstraintwave
3.4.1
FunctionFitEllipse(w,x,y):
FitFunc
Wavew
Variablex
Variabley
//w[0]=a
//w[1]=b
//w[2]=x0
//w[3]=y0
//equition:
xA2/aA2+yA/bA2=1
Return(x-w[2])A2/w[0]A2+(y-w[3])A2/w[1]A2-1
end
Make/O/N=20theta,ellipseX,ellipseYTheta=2*pi/20*p
ellipseX=2*cos(theta)+2ellipseY=3*sin(theta)+1
DisplayellipseYvsellipseX
Modifygraphmode=3,marker=8
Modifygraphwidth={perUnit,72,bottom},height={perUnit,72,left}
Modifygraphwidth={perUnit,72,bottom},height={perUnit,72,left}
Setrandomseed0.5
ellipseX+=gnoise(.3)
ellipseY+=gnoise(.3)
Duplicate/OellipseY,ellipseYFit,ellipseXFit
Make/D/OellipseCoefs={3,2,1,2}//a,b,x0,y0
FuncFit/ODR=3FitEllipse,ellipseCoefs/X={ellipseX,ellipseY}/XD={ellipseXFit,ellipseYFit}
AppendToGraphellipseYFitvsellipseXFit
Make/O/N=(100,100)elllipseContour
SetScale/Ix-3,4.5,elllipseContour
SetScale/Iy-3,5,elllipseContourelllipseContour=FitEllipse(ellipseCoefs,x,y)AppendMatrixContourelllipseContour
ModifyContourelllipseContourlabels=0,autoLevels={*,*,0},moreLevels=0,moreLevels={0}
ModifyContourelllipseContourrgbLines=(0,0,0)
3.4.2
Make/O/N=20data1
Setscale/Ix,-2,2,data1
Setrandomseed0.5
Data1=abs(x)+gnoise(0.1)
Displaydata1
Modifygraphmode=3,marker=8
Functionmyfit(w,x):
FitFunc
Wavew
Variablex
If(x>=0)
Returnw[0]+w[1]*x
Endif
If(x<0)
Returnw[2]-w[3]*x
Endif
End
Make/O/N=4co
Co={0,1,0,1}
FuncFit/W=0/NTHR=0myfit,co,data1/D
3.4.3
Functionmyfitfunc(pw,yw,xw):
FitFunc
Wavepw,yw,xw
Yw=
Endduplicateywtmp