This example illustrates some of the basic commands used in code that Diagnostic Feature Designer generates. The example shows how to use these commands to create a workspace ensemble from a table, perform member-by-member computations for a new feature, and create a feature table and an ensemble table from the workspace ensemble.
Interacting with a workspace ensemble is similar to interacting with a file ensemble datastore or a simulation ensemble datastore. Many of the commands are the same. Unlike the ensemble datastores, which allow interaction with external files, the workspace ensemble datastore enables interaction with data in memory.
Create a Workspace Ensemble from a Table
Load the ensemble table dataTable
, which contains 16 members, each of which contain timetables with vibration and tacho data along with a scalar fault code.
Create a workspace ensemble wensemble
from dataTable
, specifying the data variables and condition variables corresponding to the variables in dataTable
.
wensemble =
workspaceEnsemble with properties:
DataVariables: [2x1 string]
IndependentVariables: [0x0 string]
ConditionVariables: "faultCode"
SelectedVariables: [3x1 string]
ReadSize: 1
NumMembers: 16
LastMemberRead: [0x0 string]
Processing the data and extracting features requires only Vibration
and Tacho
. Specify SelectedVariables
to contain Vibration
and Tacho
.
Compute Mean of Vibration Signal for First Ensemble Member
The mean of the vibration signal represents a scalar feature for each member. Compute this feature for the first member, using an approach that scales to a loop that processes multiple members.
Reset the ensemble and read the first member.
m=1×2 table
Vibration Tacho
__________________ __________________
{6000x1 timetable} {6000x1 timetable}
Extract the vibration data from the member table m
.
Compute the mean value of the vibration.
Append the results to m
.
m=1×3 table
Vibration Tacho Data_Mean
__________________ __________________ _________
{6000x1 timetable} {6000x1 timetable} 0.021809
Add New Feature to Ensemble Variables
To incorporate the updated member into wensemble
, you must first specify the new Data_Mean
feature as an ensemble variable. Add Data_Mean
to the set of ensemble data variables dv
using dot notation.
Append Updated Member Table to Workspace Ensemble
Append the updated member table to the ensemble using the writeToLastMemberRead
command.
Loop Through Remaining Ensemble Members
Perform the same member-specific steps for the remaining ensemble members.
Create Feature Table and Ensemble Table from Workspace Ensemble
Extract the feature table from wensemble
with the readFeatureTable
command. View the first three rows.
faultCode Data_Mean
_________ __________
0 0.021809
1 -0.0092964
1 -0.46431
The feature table contains the condition variable FaultCode
and the data variable Data_Mean
.
Set the SelectedVariables
property to include all variables so that the resulting ensemble table contains all your information.
wensemble =
workspaceEnsemble with properties:
DataVariables: [3x1 string]
IndependentVariables: [0x1 string]
ConditionVariables: "faultCode"
SelectedVariables: [4x1 string]
ReadSize: 1
NumMembers: 16
LastMemberRead: [0x0 string]
Use the datastore command readall
to convert the workspace ensemble into an ensemble table.
tensemble=16×4 table
Vibration Tacho Data_Mean faultCode
__________________ __________________ __________ _________
{6000x1 timetable} {6000x1 timetable} 0.021809 0
{6000x1 timetable} {6000x1 timetable} -0.0092964 1
{6000x1 timetable} {6000x1 timetable} -0.46431 1
{6000x1 timetable} {6000x1 timetable} 0.4922 1
{6000x1 timetable} {6000x1 timetable} 0.3923 1
{6000x1 timetable} {6000x1 timetable} -0.12383 1
{6000x1 timetable} {6000x1 timetable} 0.42548 1
{6000x1 timetable} {6000x1 timetable} -0.4598 1
{6000x1 timetable} {6000x1 timetable} 0.062685 0
{6000x1 timetable} {6000x1 timetable} 0.059155 0
{6000x1 timetable} {6000x1 timetable} 0.037965 0
{6000x1 timetable} {6000x1 timetable} 0.53982 1
{6000x1 timetable} {6000x1 timetable} 0.52377 1
{6000x1 timetable} {6000x1 timetable} 1.0357 1
{6000x1 timetable} {6000x1 timetable} 1.0592 1
{6000x1 timetable} {6000x1 timetable} -0.94084 1
The table includes the original signals and the new feature.