Orthogonal Distance Regression fitting in a for loop

Hi,

I am doing a linear fit to different columns in 2D wave. Accesing to different datasets is in for loops and because of this I also have errors in X wave, I want to do Orthogonal Distance Regression with X weightings.
When I am doing a regular line fitting I don't have any problems to append fitting results for different datasets in separate plots. But, when I choose flag /ODR=2 for ODR fitting, all the fitting results written in the resulting waves "fit_*" have zero values and there is no problems with resulting coefficients and residuals waves. Which flags I have to consider in the command line for ODR fitting?

My code looks like:


Function PlotInputDataAndFit(w2D,numberOfI,numberOfpH)
	Wave w2D				// 2-D wave containing data
 
 	Variable numberOfI 
 	Variable numberOfpH 
 
			
 //determining positions of data in columns
			Variable i, j 			// Column for determining X and Y values	
			Make/O/T ionic = {"15","30","50","75","100","175"}
			String wTitle 		//the title of the graph
			String graphName = ""
		For (i=0; i<numberOfI;i+=1)
			For (j=0;j<numberOfpH;j+=1)
			wTitle = "pH=" + num2str(j+3)+ ", " + "I=" + ionic[i]
			Display /W=(5,45,1053,767) w2D[][48*i+6*j+4] vs w2D[][48*i+6*j+2] as wTitle
			ModifyGraph frameStyle=frameStyle
			ModifyGraph mode=3,marker=19
 			
 			// /N suppresses screen updates during fitting
			// /Q suppresses history output during fitting
			//CurveFit/N/Q/NTHR=0 line w2D[][48*i+6*j+4] /X=w2D[][48*i+6*j+2] /D /R 	
 			CurveFit/N/Q/NTHR=0/ODR=2 line w2D[][48*i+6*j+4] /X=w2D[][48*i+6*j+2] /W=w2D[][48*i+6*j+5]/XW=w2D[][48*i+6*j+3] /D /R /I=1 
 			wave w=$("fit_"+ nameOfWave(w2D))
 			wave wR=$("Res_"+ nameOfWave(w2D))
 			//Save the coefficients
 			Duplicate/O w $("fit_"+"pH" + num2str(j+3) + "I" + ionic[i]+"_"+ nameOfWave(w2D))
 			Duplicate/O W_coef $("coef_"+"pH" + num2str(j+3) + "I" + ionic[i]+"_"+ nameOfWave(w2D))
 			//Save residuals
 			Duplicate/O wR $("Res_"+"pH" + num2str(j+3) + "I" + ionic[i]+"_"+ nameOfWave(w2D))
 			//Save errors
 			Duplicate/O W_sigma $("Sigma_"+"pH" + num2str(j+3) + "I" + ionic[i]+"_"+ nameOfWave(w2D))
 			wave w1=$("fit_"+"pH" + num2str(j+3) + "I" + ionic[i]+"_"+ nameOfWave(w2D))
 			wave wR1=$("Res_"+"pH" + num2str(j+3) + "I" + ionic[i]+"_"+ nameOfWave(w2D))
 			appendToGraph w1
 			removeFromGraph/z $nameOfWave(w)
 			
		endfor
		endfor
End


The file with data is attached bellow and this file was imported in Igor as 2D wave.
I am running this function as e.g. PlotInputDataAndFit(wave0, 3,3).

Thanks for any suggestions.
Dejan
DLS_Igor.txt (144.47 KB)