How can i save and access data in a mat file.
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Lameed Onigbanjo
il 11 Mag 2018
Commentato: Lameed Onigbanjo
il 13 Mag 2018
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 Commento
Adam
il 11 Mag 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.
Risposta accettata
Stephen23
il 11 Mag 2018
Modificato: Stephen23
il 11 Mag 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:
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Tables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!