MATLAB Answers

0

How to read data from text file into class?

Asked by Heidi Mäkitalo on 8 Jul 2019
Latest activity Answered by Oriol Brasco on 8 Jul 2019
I have txt-files such as the one attached, where there are first lines describing the data in the file and then a table containing all the numeric data. I have a class in my mat-file and within it the following properties:
classdef measurement_data
properties
t0 = 0 % [datetime] start time of the measurement in CET time. 0 if not known.
dt = 0 % [s] delta t in seconds
data = [] % [] measurement data
time = []
name = '' % name of the measured data
unit = '' % unit of the measured data
metadata = '' % additional information about the measurement. For example comment field from a measurement file.
end
end
How, now, can I read data from a text file and create objects out of the different recorded signals? Each signal in the same file has the same start time, delta t, and time, but they all have different measurement data, names, and units. In different tutorials about OOP in Matlab, I've usually just seen an example where they set the value of a property manually, for example like this:
SD1_SPEED_MEASURED_1 = measurement_data;
SD1_SPEED_MEASURED_1.dt = 300;
But how would I go about setting the value by reading it from the data?
I hope it's at least somewhat clear what I'm going for, as I would really appreciate it if someone could explain this to me or point me to some documentation that might be helpful because my googling has done little to help me.

  0 Comments

Sign in to comment.

1 Answer

Answer by Oriol Brasco on 8 Jul 2019

Hello,
try using uiimport (in command window). It will help you to select the data you want and save it. Also, you could generate scripts in order to automatize the data obtention. Documentation:

  0 Comments

Sign in to comment.