CreateData function in MBC, selecting variables from a .mat file
显示 更早的评论
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
采纳的回答
更多回答(1 个)
Richard
2011-6-10
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);
类别
在 帮助中心 和 File Exchange 中查找有关 Data Manipulation Scripting 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!