CreateData function in MBC, selecting variables from a .mat file

조회 수: 4 (최근 30일)
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

채택된 답변

Ian Noell
Ian Noell 2011년 6월 9일
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
  댓글 수: 1
Dylan Finley
Dylan Finley 2011년 6월 9일
Hi Ian, thanks for your help. Are you saying that this dialog box will not appear on more recent versions of MATLAB? I am running on R2007b. Also, I am not sure how I would convert the .mat file variables into an mbcStruct using script. Would you be able to detail that for me?
Thanks, Dylan

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Richard
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);

카테고리

Help CenterFile Exchange에서 Call C from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by