Effacer les filtres
Effacer les filtres

working with 3-D Numpy array from PYTHON in MATLAB

3 vues (au cours des 30 derniers jours)
Telema Harry
Telema Harry le 6 Oct 2021
Commenté : Telema Harry le 7 Oct 2021
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.
  2 commentaires
Telema Harry
Telema Harry le 7 Oct 2021
Thank you. This solved the problem

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by