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

2 views (last 30 days)
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 1000x16. 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.
  1 Comment
Adam
Adam on 11 May 2018
I would probably store pressure as its own array. Trying to embed information like that into a variable name doesn't work well and is messy when you actually want to interpret it.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 11 May 2018
Edited: Stephen23 on 11 May 2018
"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:

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!