Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Issue with ListPlot3D Mathematica

  1. Feb 9, 2015 #1
    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:

    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}];

    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;
  2. jcsd
  3. Feb 11, 2015 #2


    Staff: Mentor

    I think that what you need is:


    The problem is that data is a list of lists of coordinates (each coordinate being a list of 3 coordinates, in your case wavelength, time, and bgcorr). ListPlot3D expects a list of coordinates, not a list of lists of coordinates. Flatten flattens out the top level of the list.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Issue ListPlot3D Mathematica Date
Issues Replicating Simulink Model within MATLAB (2DOF) Mar 11, 2017
MATLAB sum loop issue Feb 18, 2016
MATLAB plotting issue Oct 21, 2015
Maxima questions and issues Feb 11, 2015
Mathematica - ListPlot3D - Any help much appreciated Nov 26, 2004