CreateData function in MBC, selecting variables from a .mat file
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Ian Noell
il 9 Giu 2011
Dylan,
The appearance of the dialog was a bug that was fixed for R2009b. Can you please confirm which version of MBC you are using?
Loading data from a MAT file is not supported at the command-line as it is necessary to know what variables from the MAT file should be loaded into MBC. The dialog you saw allowed you to select the variables to load into MBC. However, using a dialog at the command-line is not acceptable as it interrupts the flow of a program.
An alternative is to load the MAT file in your own script and build a structure with the fields required by model.data.ImportFromMBCDataStructure. You can then use ImportFromMBCDataStructure to import data into a model.data object.
Hope that helps,
Ian
Più risposte (1)
Richard
il 10 Giu 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);
0 Commenti
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!