Matfile modify the variable of a structure

조회 수: 4 (최근 30일)
V.D-C
V.D-C 2020년 5월 18일
댓글: Michael Shagam 2021년 3월 30일
Hello all
I need advices on how to use matfile().
I have a .mat file which is a structure. This file is called '2019hydro.mat' and is a structure subdivided into 9 330x300x365 matrices.
When I load the file I have the structure 'global_structure' subdivided into the 9 matrices ('smb', 'albedo', 'abl' etc...)
Everyday there are 9 330x300 matrix that I calculate to iterate in this global_structure depending on the day. Let's say we are the 31st of December, for the variable 'smb' I will write :
global_structure.smb(:, :, 365) = calculated_smb;
Because this structure is really heavy, I was advised to use matfile().
To test my code, I wrote :
m = matfile('2019hydro.mat', 'Writable', true)
And normally to iterate the calculated matrices I would write:
m.global_structure.smb(:, :, 365) = calculated_smb;
But I get an error message saying "Cannot index into 'global_structure' because MatFile objects only support '()' indexing." .
However when I open 'm' in the workspace I have 2 structures: 'properties', and 'global_structure' which has my 9 330x300x365 matrices.
Why can I see the matrices in my 'global_structure' by clicking on it from the workspace, but I can't access it from the command window by typing 'm.global_structure.smb' ? I also tried doing an imagesc to display the data on a specific day (eg: imagesc(m.global_structure.smb(:, :, 364) ) but I have the same error message.
How can I get rid of this issue ?
Thanks for your help !
ps: I can't upload the file because of its size, I hope I was clear enough. In case I wasn't, I will explain my issue again more clearly.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 18일
matfile does not support indexing into the struct fields. Read the limitations here: https://www.mathworks.com/help/releases/R2020a/matlab/ref/matlab.io.matfile.html#mw_cd9f9130-9398-4df9-9729-070d19d4c781
You will need to modify the complete struct
m = matfile('2019hydro.mat', 'Writable', true)
temp = m.global_structure;
temp.smb(:, :, 365) = calculated_smb;
m.global_structure = temp;
  댓글 수: 2
V.D-C
V.D-C 2020년 5월 19일
Hopefully it will be implemented in Matlab's next version.
Thank you very much for your answer, it works like a charm !
Michael Shagam
Michael Shagam 2021년 3월 30일
Doesn't this defeat the purpose of the matfile function of not loading whole variables into memory? Executing
temp = m.global_structure
reads the entire structure global_structure into memory

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by