Hello, I'm new to Igor programming, so the following is probably a very simple problem. I'm also not very good at programming, so I apologize if the code below is a little naive/crude. I have a matrix named, RD7_Efield_490V, which is a 116 row by 60 column matrix. I also have a wave named, CorrectionFactor, which has 116 rows. I want the first value in row 0 of CorrectionFactor to be multiplied by each element in row 0 of matrix RD7_Efield_490V. Then the second value in row 1 of CorrectionFactor to be multiplied by each element in row 1 of matrix RD7_Efield_490V. When its all done, I would like a new matrix RD7_Efield2_490V, with the same # of rows and columns as RD7_Efield_490V. When I run the code below, I only get one value in the RD7_Efield2_490V matrix (which is incorrect in value, so I'm not quite sure what got multiplied with what). What I tried is in the attached file (I couldn't get it to fit in the post).
Thanks in advance for your help!
I have a matrix named, RD7_Efield_490V, which is a 116 row by 60 column matrix. I also have a wave named, CorrectionFactor, which has 116 rows. I want the first value in row 0 of CorrectionFactor to be multiplied by each element in row 0 of matrix RD7_Efield_490V.
The programming is only one of the issues here, it is your problem description that needs improving.
Your explanation implies only 2 for/end for loops, yet your code has 3.
Your explanation says "I want the first value in row 0 of Correction Factor", yet there is only one value in row 0 of the Correction Factor wave, since it has 116 rows and no columns are mentioned nor are they indexed in your code.
Taking a wild guess, do you actually want to multiply each column of your RD7_Efield_490V matrix by the CorrectionFactor vector?
That would simply be:
RD7_Efield_490V *= CorrectionFactor[p]
which modifies the wave in-place.
If you want a new wave to hold the result, you need another wave name:
I put your attachment here between <igor> and </igor> tags for easy reference:
Thanks, I'll know that for next time.
Quote:
I have a matrix named, RD7_Efield_490V, which is a 116 row by 60 column matrix. I also have a wave named, CorrectionFactor, which has 116 rows. I want the first value in row 0 of CorrectionFactor to be multiplied by each element in row 0 of matrix RD7_Efield_490V.
The programming is only one of the issues here, it is your problem description that needs improving.
Your explanation implies only 2 for/end for loops, yet your code has 3.
Your explanation says "I want the first value in row 0 of Correction Factor", yet there is only one value in row 0 of the Correction Factor wave, since it has 116 rows and no columns are mentioned nor are they indexed in your code.
Taking a wild guess, do you actually want to multiply each column of your RD7_Efield_490V matrix by the CorrectionFactor vector?
That would simply be:
RD7_Efield_490V *= CorrectionFactor[p]
which modifies the wave in-place.
If you want a new wave to hold the result, you need another wave name:
I suppose what had me confused is that I was working with the numbers across each row. These matrices where images that I had loaded into Igor, and I was working calculations down a column of pixels, but looking at the digitized values of the image in Igor, that column was actually a row in the table (hopefully that made sense). Either way, what you said helped, only that:
RD7_Efield_490V *= CorrectionFactor[q]
It was q that I needed and not p. Thanks again! Will try to explain better next time.
Wave RD7_Efield_490V, CorrectionFactor
Variable kfactor = DimSize(CorrectionFactor,0)
Variable numRows = DimSize(RD7_Efield_490V,0)
Variable numCols = DimSize(RD7_Efield_490V,1)
Variable i,j,k
for(i = 0;i<kfactor;i+=1)
for(j=0;j<numRows;j+=1)
for( k=0;k<numCols;k+=1)
MatrixOP/O RD7_Efield2_490V = CorrectionFactor[i]*RD7_Efield_490V[j][k]
endfor
endfor
endfor
END
The programming is only one of the issues here, it is your problem description that needs improving.
Your explanation implies only 2 for/end for loops, yet your code has 3.
Your explanation says "I want the first value in row 0 of Correction Factor", yet there is only one value in row 0 of the Correction Factor wave, since it has 116 rows and no columns are mentioned nor are they indexed in your code.
Taking a wild guess, do you actually want to multiply each column of your RD7_Efield_490V matrix by the CorrectionFactor vector?
That would simply be:
RD7_Efield_490V *= CorrectionFactor[p]
which modifies the wave in-place.
If you want a new wave to hold the result, you need another wave name:
Duplicate/O RD7_Efield_490V, RD7_Efield_490V_Corr
RD7_Efield_490V_Corr= RD7_Efield_490V * CorrectionFactor[p]
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
June 9, 2011 at 11:57 am - Permalink
I suppose what had me confused is that I was working with the numbers across each row. These matrices where images that I had loaded into Igor, and I was working calculations down a column of pixels, but looking at the digitized values of the image in Igor, that column was actually a row in the table (hopefully that made sense). Either way, what you said helped, only that:
RD7_Efield_490V *= CorrectionFactor[q]
It was q that I needed and not p. Thanks again! Will try to explain better next time.
June 9, 2011 at 12:18 pm - Permalink