
loop for a+bx using multiple waves and indices??

appaloosahotdog
the loop will calculate y from 12 different x waves. each 1D x wave has multiple values. the x waves are called ion0, ion1, ..., ion11
the coefficients a and b are derived from 12 different coefficient waves in which p=0 defines a and p=1 defines b.
the coefficient waves are called coeff0, coeff1, ... coeff11. so a of coeff0 is coeff0[0] and b of coeff0 is coeff0[1].
the loop will need to cycle through all point values in each ion wave before moving on to the next ion and coefficient.
the name of the destination wave will also need to coordinate with ion values.
i have tried to use a matrixop in a for loop to deal with this problem, but my attempts have been unsuccessful.
the current data i'm using is derived from a larger procedure which can be found at the bottom of this post. pertinent files for loading are attached (open snow.txt first and ionconcentrations.txt second)
my code looks like this:
for(index = 0; index<12; index+=1) for(i=0; i<5; i+=1) matrixop $("CalcConc"+num2str(index))= $("coeff"+num2str(index))[0] + $("coeff"+num2str(index))[1] * $("ion"+num2str(index))[i] endfor endfor
this method doesn't work for reasons that are probably obvious to more experienced igor users than me (1month).
i'd really appreciate some assistance if anyone sees the way through this problem.
thanks in advance!
Ryan
#pragma rtGlobals=3 // Use modern global access method and strict wave access. Function load(pathName, filePath) string pathName, filePath if (strlen(filePath) == 0) Open/D/R/P=$pathName refNum as filePath if (strlen(S_fileName) == 0) return -1 endif filePath = S_fileName endif LoadWave/J/D/K=2/A/V={""," $",0,0}/L={0,0,0,0,1}/P=$pathName filePath wave/T wave0 Extract4thColumn(wave0) wave Sig1 make/o/N=(numPnts(Sig1)) PeakArea PeakArea = Sig1 MatrixOp/o PeakArea = replace(PeakArea, NaN, 0) variable index string name, name2 make/o/N=10 tempwave for(index = 0; index<12; index+=1) name = "PA" + num2str(index) name2 = "ion" + num2str(index) extract/o PeakArea, tempwave, p>=14*index && p<=14*index + 13 duplicate tempwave, $name duplicate tempwave, $name2 endfor killwaves tempwave make/o/N=14 ion0, ion1, ion2, ion3, ion4, ion5, ion6, ion7, ion8, ion9, ion10, ion11 deletepoints 0, 10, ion0, ion1, ion2, ion3, ion4, ion5, ion6, ion7, ion8, ion9, ion10, ion11 edit ion0, ion1, ion2, ion3, ion4, ion5, ion6, ion7, ion8, ion9, ion10, ion11 make/o/N=10 PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11 edit PeakArea appendtotable PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11 load2("","") wave conc0, conc1, conc2, conc3, conc4, conc5, conc6, conc7, conc8, conc9, conc10, conc11 string nom, nom2 for(index = 0; index<12; index+=1) nom = "Coeff" + num2str(index) nom2 = "SD" + num2str(index) CurveFit/NTHR=0 line $("Conc"+num2str(index)) /X=$("PA"+num2str(index)) wave w_coef, w_sigma duplicate w_coef, $nom duplicate w_sigma $nom2 appendtotable $nom, $nom2 endfor wave coeff0, coeff1, coeff2, coeff3, coeff4, coeff5, coeff6, coeff7, coeff8, coeff9, coeff10, coeff11 variable i for(index = 0; index<12; index+=1) for(i=0; i<5; i+=1) matrixop $("CalcConc"+num2str(index))= $("coeff"+num2str(index))[0] + $("coeff"+num2str(index))[1] * $("ion"+num2str(index))[i] endfor endfor End Function load2(pathName, filePath) string pathName, filePath if (strlen(filePath) == 0) Open/D/R/P=$pathName refNumas filePath if (strlen(S_fileName) == 0) return -1 endif filePath = S_fileName endif LoadWave/J/D/O/K=1/A/B="N='Concentration';"/P=$pathName filePath wave Concentration variable index string name make/o/N=10 tempwave edit Concentration appendtotable for(index=0; index<12; index+=1) name = "Conc" + num2str(index) extract/o Concentration, tempwave, p>=10*index && p<=10*index + 9 duplicate/o tempwave, $name appendtotable $name endfor killwaves tempwave End Function Extract4thColumn(w) wave/T w w = ReplaceString("\t\t",w[p], "\t") make/d/o/n=(DimSize(w,0)) Sig1 Sig1 = str2num(StringFromList(3, w[p], "\t")) End
This is not going to work because MatrixOP does not support any strings on the right hand side of the equation.
The packing of your coefficients (a) and (b) leave something to be desired. I'd rearrange them as separate waves wa={a[i]} and wb={b[i]}, then concatenate all the x waves as columns of a matrix, say wavex. The result would be a simple matrix equation:
A.G.
WaveMetrics, Inc.
July 3, 2014 at 02:47 pm - Permalink