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.

I am using Mathematica 7 and I need to export a table of data and the corresponding x and y arrays. I would like to format them as a single file, say grid.h5, and need the arrays named for import in a different program. Unfortunately, applying the command:

Export["MGfunc.h5", {data, x1, y1}, {"Datasets", {"MGfunc", "x", "y"}}]

only seems to save the last array in the file MGfunc.h5.

Does anyone know how to get this working using the HDF5 format?

Here is an example:

In[13]:=  ki = N[Table[i, {i, 0, 3}]] 
kj = N[Table[j, {j, 0, 3}]] 
testgrid = Table[ki*kj, {ki, 0, 3}, {kj, 0, 3}] 

Out[13]= {0., 1., 2., 3.} 
Out[14]= {0., 1., 2., 3.} 
Out[15]= {{0, 0, 0, 0}, {0, 1, 2, 3}, {0, 2, 4, 6}, {0, 3, 6, 9}} 

In[16]:= Export["testgrid.h5", {testgrid, ki, kj}, {"Datasets", {"gridtest", "x", "y"}}] 
Out[16]= "testgrid.h5" 

In[19]:= Import["testgrid.h5"] 
Out[19]= {"/y"} 

In[20]:= Import["testgrid.h5", "Data"] 
Out[20]= {{0., 1., 2., 3.}}
share|improve this question
    
Can you give a specific example of the values of the arrays data, x1, and y1? I tried the last example from the HDF5 documentation in Mathematica 9 and it seemed to work correctly exporting two matrices: Export["test.h5", {{{1, 2}, {2, 3}}, {{10, 11}, {12, 13}}}, {"Datasets", {"m1", "m2"}}] –  Andrew Moylan Jun 14 '13 at 14:51
    
I tried this example in Mathematica 7 also, and it didn't work. Here's another example: In[13]:= ki = N[Table[i, {i, 0, 3}]] kj = N[Table[j, {j, 0, 3}]] testgrid = Table[ki*kj, {ki, 0, 3}, {kj, 0, 3}] Out[13]= {0., 1., 2., 3.} Out[14]= {0., 1., 2., 3.} Out[15]= {{0, 0, 0, 0}, {0, 1, 2, 3}, {0, 2, 4, 6}, {0, 3, 6, 9}} In[16]:= Export["testgrid.h5", {testgrid, ki, kj}, {"Datasets", {"gridtest", "x", "y"}}] Out[16]= "testgrid.h5" In[19]:= Import["testgrid.h5"] Out[19]= {"/y"} In[20]:= Import["testgrid.h5", "Data"] Out[20]= {{0., 1., 2., 3.}} –  Angela Jun 14 '13 at 19:23
1  
seems to be a bug in the export of version 7 only. It works for me with 6.0.2,8.0.4,9.0.1 on windows but not with 7.0.1. Import/Export seems to be done using an external executable connected with MathLink. Maybe one could try to exchange just that in version 7... –  Albert Retey Jun 15 '13 at 12:50

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.