Create a file ensemble datastore for data stored in MATLAB® files, and configure it with functions that tell the software how to read from and write to the datastore. (For more details about configuring file ensemble datastores, see File Ensemble Datastore with Measured Data.)
The functions tell the read
and writeToLastMemberRead
commands how to interact with the data files that make up the ensemble. Thus, when you call the read
command, it uses readBearingData
to read all the variables in fensemble.SelectedVariables
. For this example, readBearingData
extracts requested variables from a structure, bearing
, and other variables stored in the file. It also parses the filename for the fault status of the data.
Specify variables to read, and read them from the first member of the ensemble.
data=1×3 table
label gs load
________ _______________ ____
"Faulty" {5000x1 double} 0
You can now process the data from the member as needed. For this example, compute the average value of the signal stored in the variable gs
. Extract the data from the table returned by read
.
You can write the mean value gsmean
back to the data file as a new variable. To do so, first expand the list of data variables in the ensemble to include a variable for the new value. Call the new variable gsMean
.
fensemble =
fileEnsembleDatastore with properties:
ReadFcn: @readBearingData
WriteToMemberFcn: @writeBearingData
DataVariables: [5x1 string]
IndependentVariables: [0x0 string]
ConditionVariables: "label"
SelectedVariables: [3x1 string]
ReadSize: 1
NumMembers: 5
LastMemberRead: "/tmp/Bdoc24b_2725827_2687332/tp232afcfc/predmaint-ex34165887/FaultData_01.mat"
Files: [5x1 string]
Next, write the derived mean value to the file corresponding to the last-read ensemble member. (See Data Ensembles for Condition Monitoring and Predictive Maintenance.) When you call writeToLastMemberRead
, it converts the data to a structure and calls fensemble.WriteToMemberFcn
to write the data to the file.
Calling read
again advances the last-read-member indicator to the next file in the ensemble and reads the data from that file.
data=1×3 table
label gs load
________ _______________ ____
"Faulty" {5000x1 double} 50
You can confirm that this data is from a different member by examining the load
variable in the table. Here, its value is 50, while in the previously read member, it was 0.
You can repeat the processing steps to compute and append the mean for this ensemble member. In practice, it is more useful to automate the process of reading, processing, and writing data. To do so, reset the ensemble to a state in which no data has been read. Then loop through the ensemble and perform the read, process, and write steps for each member.
The hasdata
command returns false
when every member of the ensemble has been read. Now, each data file in the ensemble includes the gsMean
variable derived from the data gs
in that file. You can use techniques like this loop to extract and process data from your ensemble files as you develop a predictive-maintenance algorithm. For an example illustrating in more detail the use of a file ensemble datastore in the algorithm-development process, see Rolling Element Bearing Fault Diagnosis. The example also shows how to use Parallel Computing Toolbox™ to speed up the processing of large data ensembles.
To confirm that the derived variable is present in the file ensemble datastore, read it from the first and second ensemble members. To do so, reset the ensemble again, and add the new variable to the selected variables. In practice, after you have computed derived values, it can be useful to read only those values without rereading the unprocessed data, which can take significant space in memory. For this example, read selected variables that include the new variable, gsMean
, but do not include the unprocessed data, gs
.
data1=1×3 table
label load gsMean
________ ____ ________
"Faulty" 0 -0.22648
data2=1×3 table
label load gsMean
________ ____ ________
"Faulty" 50 -0.22937