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

조회 수: 2 (최근 30일)
Lameed Onigbanjo
Lameed Onigbanjo 2018년 5월 11일
댓글: Lameed Onigbanjo 2018년 5월 13일
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
Adam
Adam 2018년 5월 11일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2018년 5월 11일
편집: Stephen23 2018년 5월 11일
"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:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by