フィルターのクリア

Save classdef with Object in MAT file

9 ビュー (過去 30 日間)
Oren Lee
Oren Lee 2020 年 11 月 4 日
回答済み: Steven Lord 2020 年 11 月 8 日
Hello fellow MATLABIANs-
I have what is hopefully a simple question, and whether there is a workaround or not.
I regularly process huge amounts of data, all of different parameter names samplerates etc (measurements with thermocouples, accelerometers etc). Typically I process all my data into one MAT file with each variable names something like "Thermocouple_01", with all the necessary data and tags within it as a structure. A typical file can have a few down to a few hundred of these variables in them depending on test instances. This process works well for most of what I need, but there are instances in my later postprocessing processing scripts where it breaks down. Additionally, data I produce is consumed by an ever increasing number of people, and keeping data well defined with names like this assists everyone down the line.
Something I did recently was help this process by defining a class definition including properties like "startTime", "samplerate", etc. I save these new objects in place of the parameters mentioned above. This has the advantage of allowing me to sort data based on my classes making postprocessing much easier, but makes it impossible for anyone without the class definition to open the file. As mentioned above, the list of people I hand data over to is ever increasing, and sending everyone the definition in not feasible.
So the question for you the community is: Is it possible to save the classdef in the same MAT file as the objects themselves? Meaning if someone did not have the ".m" file with the classdef, they could still open the file into their workspace.
Thanks so much for the help and look forward to hearing your suggestions!
  1 件のコメント
per isakson
per isakson 2020 年 11 月 8 日
AFAIK: The only way to save a "classdef" in a mat-file is to save it as string. To use the class
  • write the string to a file, e.g. MyMetaData.m
  • create an anonymous function, af = @(x,...) MyMetaData(x,...);
  • delete the file
  • use af to create instancies of MyMetaData
However, I assume I missed the point. A minimal working example would help me to understand.

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2020 年 11 月 8 日
Typically I process all my data into one MAT file with each variable names something like "Thermocouple_01", with all the necessary data and tags within it as a structure.
Can you define variables with numbered names like X1, X2, X3, ... ? Yes.
As mentioned above, the list of people I hand data over to is ever increasing, and sending everyone the definition in not feasible.
Pushing the data to a large group of people can be problematic. Consider switching to a system where the people who need / want the data can pull it from some sort of database. One way to do this is to set up a source control system where you store your data and your code. This has a couple benefits:
  1. People who need the current data can get it without having to ask you and wait for you to respond.
  2. People who need historical data can get it from the source control system's repository.
  3. The source control system provides traceability as to who changed the source code, when they changed it, and how it changed. With good commit messages accompanying each new update to the software you can even answer why it changed.
  4. When combined with unit tests and a continuous integration system, you can validate that changes you make to your object's definition are unlikely to break other parts of the object's functionality.

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by