MATLAB: How can i save and access data in a mat file.

matvariable

I am fairly new to matlab and currently looking for the best way to save and access data to be used in a GUI. I am planning on having one .mat file and several variables which would serve as the pressure numbers and each pressure variable would be a matrix 1000×16. i would also like your suggestions on how to name the variables so that the numbers can be read for situations where interpolation between two pressures are necessary.

Best Answer

"i would also like your suggestions on how to name the variables..."
Don't name variables like that! Creating or accessing variable names is how beginners force themselves into writing slow, complex, buggy code that is hard toe debug. Just put the data into one array (which might be ND numeric, cell array, struct, table, etc.). Read this to know more:
Don't put meta-data into variable names or fieldnames. Meta-data is data too, so store it along with your other data. If I was given your data I would store it in two arrays, the first a 3D numeric array with the measurements/sample, and the second a simple vector with the corresponding pressure values (they are numeric, so storing them as numeric will make your code simpler and more efficient). Then all you need to store is this:
A = [1000x16xN] % 3D array of data
V = [1,10,100,...] % 1xN vector of pressure values
save(...,'A','V')
and load it
S = (...);
A = S.A;
V = S.V;
Of course you should use more descriptive names. Finding specific values in either array is trivial and efficient using indexing. How to use indexing is explained in the introductory tutorials:
And of course having all of the data in one array means you can trivially apply many numeric operations to it:
Related Question