필터 지우기
필터 지우기

matfile function for multidimentional arrays

조회 수: 2 (최근 30일)
Darby Paez
Darby Paez 2023년 6월 13일
편집: Stephen23 2023년 6월 13일
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