I have searched everywhere to find an answer for this and have come up with nothing!
I have a data file containing two columns, one with wavelengths in nanometer (some with decimal digits, others just with a decimal point) and the other with spectral irradiance values.
I am trying to make a new table that takes as the first column all the wavelengths and in the second column I divide the spectral values by photon energy to get photon flux. However, in this new table I want to stop at a certain index i where the wavelength corresponds to a specific photon energy that I calculated. This is the code I use. It works.
Here is a small portion of the data table:
{280., 280.5, 281., 281.5, 282., 282.5, 283., 283.5, 284., 284.5, \
SSpecUsed = Drop[Table[{SSpecWavelength[[i]],SSpecIntensity[[i]]/Eph[SSpecWavelength[[i]]]*Subscript[En, G, Si]*q /. numval}, {i, 0, 949, 1}], 1];
My issue is that I manually found the index (949) at which the wavelength is 1107. nm. In a later exercise I need to integrate over this data up to different indices (so for example integrating all the way up to wavelength 2000 and in the next step only up to 1999). So I tried replacing the 949 value by:
Position[SSpecWavelength, Subscript[\[Lambda], G][Eg_]]/.numval
So basically I try using Position to find the index at which the element in the list is equal to the wavelenght that I calculate based on an energy value. When I run it I get empty curly brackets. I even tried this:
Position[SSpecWavelength, 1107.]
and I still get empty curly brackets. I checked and I know for a fact that the element at index 949 is equal to 1107. so why does it not return me the index?
Is there another (better/simpler) way to accomplish what I want?
Thanks in advance, hope the problem is clear!
FirstPosition[SSpecWavelength, _?(# > 1107. &)]
to find the first position with a value larger than1107.
. $\endgroup$Position
may take floating point numbers more literate than you. The value from the list could be1107.0000001
or so but only the leading digits are shown. This difference may be small, butPosition
won't match1107.
with1107.0000001
. $\endgroup$FirstPosition[SSpecWavelength, _?(# > 1107. &)][[1]]
? $\endgroup$