setExternalInput "The number of external inputs must be equal to the number of root-level input port blocks"

42 views (last 30 days)
Hello
I've created a simple model for the purposes of exploring "setExternalInput." The model is called "jordanTest" as shown below. After I've set the external input and run the correspondingly modified model, I get the error below; I've compared my model's settings with those of the example from setExternalInput's documentation and they seem to be the same.
"The number of external inputs must be equal to the number of root-level input port blocks. Root-level input port blocks
include Enable blocks and Trigger blocks with 'Trigger type' set to rising, falling, or either. The model contains 3
root-level input port blocks, but 1 external inputs were specified in Configuration Parameters -> Data Import/Export ->
Input."
jordanTest_1.PNG
jordanTest_2.PNG
The error occurs after executing the last line of this code:
t=[0:1:3];
ds{1}=timeseries([1,1,1,1],t);
ds{2}=timeseries([1,2,3,5],t);
ds{3}=timeseries([6,7,4,2],t);
in = Simulink.SimulationInput('jordanTest');
in = in.setExternalInput(ds);
out=sim(in)

Answers (1)

Jordan McBain
Jordan McBain on 25 Apr 2019
I worked around this problem by doing the following:
t=[0:1:3];
mdl='jordanTest'
inports=createInputDataset(mdl);
inports{1}=timeseries([5,6,4,5],[0,1,2,3],'Name',inports{1}.Name);
inports{2}=timeseries([2,4,3,6],[0,1,2,3],'Name',inports{2}.Name);
inports{3}=timeseries([1,4,2,5],[0,1,2,3],'Name',inports{3}.Name);
in = Simulink.SimulationInput('jordanTest');
set_param(mdl,'LoadExternalInput','on');
in = in.setExternalInput(inports);
out=sim(in)
It seems as if the timeseries have to have the associated port names included.

Community Treasure Hunt

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

Start Hunting!