필터 지우기
필터 지우기

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 CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by