working with 3-D Numpy array from PYTHON in MATLAB

4 次查看(过去 30 天)
I opened GRIB2 files as a 3-D Numpy array in python and I want to save the data in a .mat file so I can can use the data in my MATLAB model.
Assuming the 3-D Numpy array has a shape of (3, 2, 4), where the 3 is the depth, 2 is the row and 4 is the column.
I can save the data in .mat files using the command:
b = np.array([[[1,2,4,2],[3,4,6,0]],[[5,7,6,1],[7,8,0,9]], [[3,1,0,1],[1,0,5,9]]])
dict = {'B':b}
sio.savemat ('/Volumes/Converted files/test.mat',dict)
The challenge:
A 3-D array of (3,2,4) is read differently in MATLAB, it is interpreted as 3 = row, 2 = column and 4 = depth.
In MATLAB, the data should have the following form (2,4,3)
My question:
Please, how will I manipulate the data in MATLAB such that it will have same meaning ?
>> b(:,:,3) = [3,1,0,1; 1,0,5,9]
b(:,:,1) =
1 2 4 2
3 4 6 0
b(:,:,2) =
5 7 6 1
7 8 0 9
b(:,:,3) =
3 1 0 1
1 0 5 9
Thank you.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by