For my work, it is convenient to store measurement data in structures with many fields. The structure is useful for keeping all the measurements together, passing into functions that plot everything, etc. However the files get large and bulky to handle. I'd like to be able to load a specified field from the *.mat file containing the structure. I thought this was possible usingthis approach (saving with -struct flag), but only separate variables containing the fields are saved and the original structure is lost. Is there a way to retrieve a field out of an existing mat file containing a structure, as is shown below, perhaps usingmatfile ?
% Make the structure
a.Temperature.value = rand(1,10);
a.Temperature.units = 'C';
a.Humidity.value = rand(1,10);
a.Humidity.units = '%';
save('c:\temp\junk.mat', 'a'); % Save the structure
load('c:\temp\junk.mat', 'a.Temperature'); % Load a specified field (doesn't work)
I was grumpy about the fact that the -struct file results in a mat file containing variables, i.e. I lose the original structure, until I realized I could regain it as shown below. However we have tons of already-saved *.mat files containing large structures which I would love to pull fields out of but sounds like that is not an option.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
0 Comments
Sign in to comment.