matfile function for multidimentional arrays

2 次查看(过去 30 天)
Hello everyone,
I am working on a code to express a field as an expansion of multipoles (6D arrays) to interact with a large number of particles. In this work, I have worked with arrays larger than 10GB. Currently, I am attempting to save the large variables into .mat files, read specific parts of the array that I require, modify them, and save them again in the large .mat file. However, I have encountered difficulties in achieving this. Let me simplify my problem to the following situation:
clear;
clc;
%% Parameters
lambda0=532e-9;
n_s=1.33;
ks=2*pi*n_s/lambda0;
r=7.5e-6;
L_max=10;
Mmax = 2*L_max + 1;
theta=linspace(1e-4,pi,111);
phi = linspace(0,2*pi,111);
[Theta,Phi]=meshgrid(theta,phi);
JJ=complex(zeros([2,L_max+1,Mmax,size(Theta),3]));% this is the big array I will be filling
A=ones(111,111,3); % here really I will use a function with do some operations but, its
% dimentions are (size(Theta),3)
save JJ.mat JJ -v7.3;
J=matfile('JJ.mat','Writable',true);
l=1;
m=2;
m_=1;
J.JJ(1, l+1, m+1, :, :,:) = A;
The size of the right hand side did not match the size of the indexing on the left hand side.
I understand that the issue lies in the dimensions of J.JJ, which is 2x11x21x111x111x3, while A has dimensions of 111x111x3. However, I still need to perform the required modifications. Specifically, I need to change the elements (1, l+1, m+1, :, :,:) of the JJ array to match the corresponding elements in array A. I am capable of accomplishing this task with a smaller array without utilizing matfile. However, considering the size of the array I am working with, do you have any ideas or suggestions on how to proceed?

采纳的回答

Stephen23
Stephen23 2023-6-13
编辑:Stephen23 2023-6-13
Why not simply PERMUTE the dimensions to A to suit?
JJ = nan(2,11,21,111,111,3);
save test.mat JJ -v7.3
clearvars
MF = matfile('test.mat','Writable',true);
A = rand(111,111,3);
l=1;
m=2;
MF.JJ(1,l+1,m+1,:,:,:) = permute(A,[4,5,6,1,2,3]);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by