matfile function for multidimentional arrays
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Darby Paez
am 13 Jun. 2023
Bearbeitet: Stephen23
am 13 Jun. 2023
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;
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?
0 Kommentare
Akzeptierte Antwort
Stephen23
am 13 Jun. 2023
Bearbeitet: Stephen23
am 13 Jun. 2023
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!