Message Boards Message Boards

Plot 3D experimental data?

Posted 8 years ago

Hi everyone, I would like to apologize upfront if the question is stupid!

I am very new to Mathematica and I am start to use it for data analysis as it looks like a very powerful tool. I have a set of data that was aquired during a experiment (I am a PhD student, chemistry) and I am trying to plot it. The experiment gives me a set of data that looks like an matrix (and it should be) and I would like to plot only 3 specific rows on a 3d map... But it looks like Mathematica is not recognizing it as a Matrix, it only has one row.

Part of the data is pasted below (I could not ad the file.. I dont see the quote marks on Mathematica...) and what I have done so far (very little as I dont know much) are in attachment, if some one could help it would be great!

DATA:

{{"#", "Sensolytics:", 1.2}, {"#", "Channels:1"}, {"#", "Channel", 1, 
  "Name:", "WE(1).Current"}, {"#", "Channel", 1, "Code:", 101}, {"#", 
  "Channel", 1, "Unit:", "nA"}, {"#", "Rows:", 65}, {"#", "Lines:", 
  10}, {"#ArrayScan"}, {"#Warning:", "the", "data-format", "is", 
  "using", "a", "'.'", "as", "decimal", "sign.", "German", 
  "Windows-systems", "may", "have", "problems", "with", 
  "this..."}, {"#", "Scan", "started:", "4/1/2016", "1:07:55", 
  "PM"}, {"#", "Mode:", "Fast", "Comb"}, {"#", 
  "X-Length:", -650}, {"#", "Y-Length:", -100}, {"#", "X-Inkrement:", 
  10}, {"#", "Y-Inkrement:", 10}, {"#", "max.", "Speed:", 15}, {"#", 
  "Waiting", "Time:", 50}, {"#", "X", "[Â\[Micro]m],", "X", "rel.", 
  "[Â\[Micro]m],Y", "[Â\[Micro]m],Y", "rel.", "[Â\[Micro]m],", "Z", 
  "[Â\[Micro]m],", "Z", "rel.", "[Â\[Micro]m],", "Channel", "1,", 
  "Channel", 
  "2,..."}, {"600.000,0.000,100.000,0.000,109.000,0.000,3.784,"}, \
{"590.000,-10.000,100.000,0.000,109.000,0.000,3.174,"}, \
{"580.000,-20.000,100.000,0.000,109.000,0.000,2.747,"}, \
{"570.000,-30.000,100.000,0.000,109.000,0.000,2.411,"}, \
{"560.000,-40.000,100.000,0.000,109.000,0.000,2.228,"}, \
{"550.000,-50.000,100.000,0.000,109.000,0.000,1.801,"}, \
{"540.000,-60.000,100.000,0.000,109.000,0.000,1.404,"}, \
{"530.000,-70.000,100.000,0.000,109.000,0.000,1.373,"}, \
{"520.000,-80.000,100.000,0.000,109.000,0.000,1.282,"}, \
{"510.000,-90.000,100.000,0.000,109.000,0.000,1.526,"}, \
{"500.000,-100.000,100.000,0.000,109.000,0.000,1.587,"}, \
{"490.000,-110.000,100.000,0.000,109.000,0.000,1.099,"}, \
{"480.000,-120.000,100.000,0.000,109.000,0.000,0.549,"}, \
{"470.000,-130.000,100.000,0.000,109.000,0.000,0.916,"}, \
{"460.000,-140.000,100.000,0.000,109.000,0.000,1.068,"}, \
{"450.000,-150.000,100.000,0.000,109.000,0.000,0.793,"}, \
{"440.000,-160.000,100.000,0.000,109.000,0.000,0.854,"}, \
{"430.000,-170.000,100.000,0.000,109.000,0.000,0.916,"}, \
{"420.000,-180.000,100.000,0.000,109.000,0.000,1.373,"}, \
{"410.000,-190.000,100.000,0.000,109.000,0.000,0.977,"}, \
{"400.000,-200.000,100.000,0.000,109.000,0.000,1.709,"}, \
{"390.000,-210.000,100.000,0.000,109.000,0.000,1.160,"}, \
{"380.000,-220.000,100.000,0.000,109.000,0.000,1.556,"}, \
{"370.000,-230.000,100.000,0.000,109.000,0.000,1.495,"},.......

Cheers

Attachments:
POSTED BY: Gabriel Meloni
6 Replies

Hi Gabriel,

it does not take this to be a matrix because some rows have only length one - in fact they are empty sets.

dat = Import["~/Downloads/Data_exp.dat", "CSV"];
Length /@ dat[[19 ;; -2]]

enter image description here

Select[dat[[19 ;; -2]], Length[#] == 8 &] // Dimensions

gives a $\{725,8\}$ matrix.

The reason why Mathematica does not take this to be a matrix originally is that the "dimensions" are inconsistent, i.e.there are empty lines. Also note that every row has 8 entries - the last one is empty. That can be fixed by:

Select[dat[[19 ;; -2]], Length[#] == 8 &][[All, 1 ;; 7]]

Cheers,

M.

POSTED BY: Marco Thiel

Thank you very much Gianluca and Marco!

The procedure work fine for "cleaning" but still does not do the trick...

It (the script) still thinks that it is a matrix with one row and 765 (or so) lines.. I wish it was a matrix of 765 lines by 7 rows...

I need to plot a 3d plot with the 1st, 3rd and 7th rows, in this case the 1st, 3rd and 7th elements of each "line" (the elements divided by "," inside the curly brackets).

When I use the suggested scrips and ask for the value of X this is what I get

{600., 0., 100., 0., 109., 0., 3.784}

Witch is the first line of the data matrix but I wish it was the first row ...(sorry if it is not clear)

I tried to transpose but says it cant...

Any Idea?

Sorry to bother you guys and thank you very much!!!

POSTED BY: Gabriel Meloni

Hi Gabriel,

Gianluca is right:

dat = Import["~/Downloads/Data_exp.dat"];
datclean = Flatten[ToExpression[StringSplit[#, ","]]] & /@ dat[[19 ;; -2]];
X = datclean[[1]]; (*Should be row 1*)
Y = 
 datclean[[3]]; (*Should be row 2 and so on...*)
Z = datclean[[5]];
Xrel = datclean[[2]];
Yrel = datclean[[4]];
Zrel = datclean[[6]];
Chanel1 = datclean[[7]];
XYplane = Riffle[X, Y];
surface = Partition[Riffle[XYplane, Chanel1, 3], 3]; 
surface // MatrixForm

gives

enter image description here

Alternatively to my cleaning function you could of course import the data differently:

dat = Import["~/Downloads/Data_exp.dat", "CSV"];

Cheers,

M.

POSTED BY: Marco Thiel

Hi Murray, Thank you for the reply! As I cannot attach this file (might be my own incompetence) I am sending a dropbox link for the file!

https://www.dropbox.com/s/vn4k3zaj9r4q7xm/Data_exp.dat?dl=0

Cheers

POSTED BY: Gabriel Meloni

It seems that the numerical part of your array is made of strings instead of numbers. You can convert the strings this way:

{{"600.000,0.000,100.000,0.000,109.000,0.000,3.784,"}, \
{"590.000,-10.000,100.000,0.000,109.000,0.000,3.174,"}, \
{"580.000,-20.000,100.000,0.000,109.000,0.000,2.747,"}, \
{"570.000,-30.000,100.000,0.000,109.000,0.000,2.411,"}} /. \
{str_String} :> ToExpression[StringSplit[StringDrop[str, -1], ","]]
POSTED BY: Gianluca Gorni

Please post a link to the actual .dat file, so we can see just what's going on here.

POSTED BY: Murray Eisenberg
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract