Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Lets say I have 2 2D arrays where each cell contains a list of values:

Example:

data_1[[1]][[1]] = {1,2,3} 
data_1[[1]][[2]] = {1,2,3} 
data_1[[2]][[1]] = {1,2,3} 
data_1[[1]][[2]] = {1,2,3} 

data_2[[1]][[1]] = {2,4,6} 
data_2[[1]][[2]] = {3,6,9} 
data_2[[2]][[1]] = {4,8,12} 
data_2[[2]][[2]] = {5,10,15} 

What's a neat way to make a discrete 3D plot of the ratio between medians of these data sets (assuming that the indices always mach, but can represent any value, not only consecutive natural numbers).For the following data I would expect a plot of:

x,y,z
1,1,2
1,2,3
2,1,4
2,2,5
share|improve this question
    
You cannot use underscore (_) in symbol names; it is reserved for patterns. Also, your format is confusing. Why don't you paste the complete nested list structure you are describing instead of the messy Set lines? –  Mr.Wizard Feb 4 '13 at 13:08
    
@Mr.Wizard thx for the heads up about "_". I didn't paste it because I don't have it yet -> see my other question link –  JohnnyM Feb 4 '13 at 13:53

1 Answer 1

up vote 2 down vote accepted
 dt1 = Array[RandomReal[1, {3}] &, {5, 5}];
 dt2 = Array[RandomReal[1, {3}] &, {5, 5}];
 {med1, med2} = Map[Median, #, {2}] & /@ {dt1, dt2};
 medratios = med1/med2;
 Row[ListPlot3D[#, BoxRatios -> 1, ImageSize -> 300] & /@ {med1, med2,  medratios},
 Spacer[5]

enter image description here

Update: per op's request in the comments, here is a version that generates data of the form {{x,y,{z1,z2,z3}}...:

 dt1xyz = Array[{10 #1, 100 #2, RandomReal[1, {3}]} &, {5, 5}];
 dt2xyz = Array[{10 #1, 100 #2, RandomReal[1, {3}]} &, {5, 5}];
 med1xyz = dt1xyz;
 med1xyz[[All, All, 3]] = Map[Median, med1xyz[[All, All, 3]], {2}];
 med2xyz = dt2xyz;
 med2xyz[[All, All, 3]] = Map[Median, med2xyz[[All, All, 3]], {2}];
 ratiosxyz = dt2xyz;
 ratiosxyz[[All, All, 3]] = 
 med1xyz[[All, All, 3]]/med2xyz[[All, All, 3]]

.. and plots:

 Row[ListPlot3D[#, BoxRatios -> 1, ImageSize -> 300] & /@ {Join @@ 
  med1xyz, Join @@ med2xyz, Join @@ ratiosxyz}, Spacer[5]]

enter image description here

share|improve this answer
    
will it handle non consecutive indices? like when x has step of 10 and y of 100; (data[[10]][[100]]). Are list suitable for this kind of indexing anyway? –  JohnnyM Feb 4 '13 at 13:57
    
@JohnnyM, x and y indices need not be consecutive; ListPlot3D also takes data in the form {{x1,y1,z1},{x2,y2,z2}...}. –  kguler Feb 4 '13 at 14:10
    
@kugler can you please update your answer so it would generate data in this format? –  JohnnyM Feb 4 '13 at 14:14
    
@JohnnyM, please see my update. –  kguler Feb 4 '13 at 15:12
    
Thank you, that should do it! –  JohnnyM Feb 4 '13 at 16:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.