- #1
Maior272
- 1
- 0
Hi everybody,
I am relatively new to Mathematica, so please don't be to harsh on me regarding beginners' mistakes ;-)
I wanted to write a script, which evaluates and plots a series of 100 spectra. Therefore I have 100 spectral data files, which provide the spectrum in the first 1340 lines and background in the second 1340 lines. Additionaly I want to normalize the spectrum with a whitelightspectrum recorded in a second file.
Hence I want to calculate (Spectrum-Background)/whitelight for each value.
Therefore I calculate all the values using 2 interlaces for loops putting the values in a table, which works fine.
My problem appears in the very last step as I want to plot the data using ListPlot3D which only returns an empty box (however it has the right dimensions).
I would appreciate very much you help :-)
Here is my source code:
ClearAll["Global`*"]
numspectra = 100;
time = 0;
data = Table[datafunc, {i1, numspectra}, {i2, 1340}, {i3, 3}];
spectrum = Table[Import["...\#1_13_" <> ToString <> ".txt", "Data"], {i, numspectra}];
whitelight = Table[Import["...\white 100spec_53_" <> ToString <> ".txt", "Data"], {u, numspectra}];
ToExpression[spectrum]
ToExpression[whitelight]
For[h = 1, h <= numspectra, h++,
time = time + 1;
For[j = 1, j <= 1340, j++,
wavelength = Part[spectrum, h, j, 1];
If[Part[whitelight, h, j, 3] == 0, Part[whitelight, h, j, 3] = 1, Null]; (*Avoid division by 0*)
bgcorr = (Part[spectrum, h, j, 3] - Part[spectrum, h, 1340 + j, 3])/ Part[whitelight, h, j, 3];
Part[data, h, j, 1] = wavelength;
Part[data, h, j, 2] = time;
Part[data, h, j, 3] = bgcorr;
]
]
ListPlot3D[data]
I am relatively new to Mathematica, so please don't be to harsh on me regarding beginners' mistakes ;-)
I wanted to write a script, which evaluates and plots a series of 100 spectra. Therefore I have 100 spectral data files, which provide the spectrum in the first 1340 lines and background in the second 1340 lines. Additionaly I want to normalize the spectrum with a whitelightspectrum recorded in a second file.
Hence I want to calculate (Spectrum-Background)/whitelight for each value.
Therefore I calculate all the values using 2 interlaces for loops putting the values in a table, which works fine.
My problem appears in the very last step as I want to plot the data using ListPlot3D which only returns an empty box (however it has the right dimensions).
I would appreciate very much you help :-)
Here is my source code:
ClearAll["Global`*"]
numspectra = 100;
time = 0;
data = Table[datafunc, {i1, numspectra}, {i2, 1340}, {i3, 3}];
spectrum = Table[Import["...\#1_13_" <> ToString <> ".txt", "Data"], {i, numspectra}];
whitelight = Table[Import["...\white 100spec_53_" <> ToString <> ".txt", "Data"], {u, numspectra}];
ToExpression[spectrum]
ToExpression[whitelight]
For[h = 1, h <= numspectra, h++,
time = time + 1;
For[j = 1, j <= 1340, j++,
wavelength = Part[spectrum, h, j, 1];
If[Part[whitelight, h, j, 3] == 0, Part[whitelight, h, j, 3] = 1, Null]; (*Avoid division by 0*)
bgcorr = (Part[spectrum, h, j, 3] - Part[spectrum, h, 1340 + j, 3])/ Part[whitelight, h, j, 3];
Part[data, h, j, 1] = wavelength;
Part[data, h, j, 2] = time;
Part[data, h, j, 3] = bgcorr;
]
]
ListPlot3D[data]