-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
You can add dicts inside .mat, which will point towards each 4D polar.
Stick with 7.3 version
from scipy.io import savemat
import numpy as np
def save_multiple_arrays_to_mat(arrays, filename='combined_data.mat'):
"""
Save multiple numpy arrays to a single .mat file
Parameters:
arrays : list of numpy.ndarray
List containing all the arrays to save
filename : str
The name of the output .mat file
"""
# Create a dictionary to store all arrays
data_dict = {}
# Add each array to the dictionary with a unique key
for i, array in enumerate(arrays):
data_dict[f'array_{i+1}'] = array
# Save the dictionary to a .mat file
savemat(filename, data_dict)
print(f"Successfully saved {len(arrays)} arrays to {filename}")
# Example usage:
# Create 30 sample arrays (4 columns × 40 rows each)
sample_arrays = [np.random.rand(40, 4) for _ in range(30)]
# Save all arrays to a single .mat file
save_multiple_arrays_to_mat(sample_arrays, 'multiple_arrays.mat')
If your arrays have specific names or meanings, you can customize the keys in the dictionary:
# If you have meaningful names for your arrays
array_names = [f'airfoil_{i+1}' for i in range(30)] # Or any custom names
data_dict = {}
for name, array in zip(array_names, arrays):
data_dict[name] = array
savemat('named_arrays.mat', data_dict)
You can also organize them into a cell array structure similar to how MATLAB might handle it:
# For a MATLAB-like cell array structure
data_dict = {'all_arrays': np.array(arrays, dtype=object)}
savemat('matlab_cell_arrays.mat', data_dict)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request