Matfile modify the variable of a structure
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
V.D-C
am 18 Mai 2020
Kommentiert: Michael Shagam
am 30 Mär. 2021
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.
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 18 Mai 2020
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 Kommentare
Michael Shagam
am 30 Mär. 2021
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Workspace Variables and MAT-Files 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!