CreateData function in MBC, selecting variables from a .mat file
Ältere Kommentare anzeigen
Hi,
I am attempting to automate an MBC process and have been reviewing the Gasoline DIVCP Project command-line example from the help files. I understand the syntax involved with CreateData and do not receive an error message. However, when I run the script, a window opens in MBC asking me to select the variables I want to use in my dataset from the .mat file I specified in my CreateData function.
My questions are:
1) Why does D = CreateData(project, datafile) not select all the variables from the .mat datafile?
2) How can I use script to select the desired variables from the .mat datafile to put into my dataset?
Thank you for any help you may offer,
Dylan
Akzeptierte Antwort
Weitere Antworten (1)
Richard
am 10 Jun. 2011
Following on from Ian's reply, here is a concrete example of importing using a data structure. The easiest and most robust way of ensuring your structure has the right format is to export an empty one and then put data into it:
% Assume "load myData" creates 4 vectors, A,B,C,D
A = rand(100,1);
B = rand(100,1);
C = rand(100,1);
D = rand(100,1);
% Create an empty data object
data = mbcmodel.CreateData;
% Get a correctly formatted structure
S = ExportToMBCDataStructure(data);
% Place data into the structure
S.varNames = {'A', 'B', 'C', 'D'};
S.data = [A(:), B(:), C(:), D(:)];
% Units and comment are optional
S.varUnits = {'km', 'inches', 'fathoms', ''};
S.comment = 'Imported from mat data';
% Import the structure into the data object
data = BeginEdit(data);
data = ImportFromMBCDataStructure(data , S);
data = CommitEdit(data);
Kategorien
Mehr zu Data Manipulation Scripting finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!