The following Matlab code create_cdf.m
:
A = reshape(1:32, 8,4);
cdfwrite('A.cdf',{'A', A});
A
creates A
matrix of 8 rows and 4 cols, writes it into CDF file and prints:
>> create_cdf
A =
1 9 17 25
2 10 18 26
3 11 19 27
4 12 20 28
5 13 21 29
6 14 22 30
7 15 23 31
8 16 24 32
And the following Mathematica notebook read_cdf.nb
:
SetDirectory[NotebookDirectory[]];
data = Import["A.cdf", "Elements"]
(* {"Annotations", "Data", "DataEncoding", "DataFormat", Datasets", "Metadata"} *)
data = Import["A.cdf", "Data"]
(* {{{{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 10., 11.,
12.}, {13., 14., 15., 16.}, {17., 18., 19., 20.}, {21., 22., 23.,
24.}, {25., 26., 27., 28.}, {29., 30., 31., 32.}}}} *)
Dimensions[data]
(* {1, 1, 8, 4} *)
data = data[[1, 1]]
(* {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 10., 11.,
12.}, {13., 14., 15., 16.}, {17., 18., 19., 20.}, {21., 22., 23.,
24.}, {25., 26., 27., 28.}, {29., 30., 31., 32.}} *)
Dimensions[data]
(* {8, 4} *)
data // TableForm
I.e. returned data has the same shape, but incorrectly filled.
UPDATE
1) If Mathematica would interpret that CDF as Computable Document Format
, it would return Notebook
. Since it returns something different, it is correctly recognizes Common Data Format
.
2) Matlab was used just as an example. I can't check Mathematica with itself, usage of other piece of software is unavoidable. I think the same results as Matlab is given by Python + CDF C
. May be need to check additionally.
Import["A.cdf", String] //Compress
so that we can inspect the contents of the file. $\endgroup$"NASACDF"
format. However, Mathematica (as of version 11.1.1) only supports version 3.1 and earlier of the NASACDF format. I suggest checking that the version being exported is by Matlab is 3.1 or earlier. You can also be more specific with yourImport
by specifying the file format;Import["A.cdf", {"NASACDF", "Elements"}]
. $\endgroup$