Brace indexing is not supported for variables of this type

조회 수: 3 (최근 30일)
Hi,
I want to use a SimulationInput object as an argument for "sim()" because it seems to work with simulink compiler.
The error
Error using SimulationClass/runSimulation (line 63)
Brace indexing is not supported for variables of this type.
Error in testclass (line 3)
myobj.runSimulation(); - Show complete stack trace
ocurrs when the method runSimulation is run.
I can't figure out exactly why this is happening. It does run fine when I use the modelname, that is a string: sim(modelName).
The "sim" command isn't shadowed. I get an error when I use it without any arguments as well.
Maybe something is wrong with my SimulationInput object. I added the output of SimIn.
% testclass.m
function testclass()
myobj = SimulationClass('Bremsscheibensimulation_Simulation', "AMS-TEST", "input_script"); %, user_data_struct);
myobj.runSimulation();
end
% SimulationClass.m
function runSimulation(obj)
obj.saveParamsToFile()
simIn = Simulink.SimulationInput(obj.simModelName);
simIn = simIn.loadVariablesFromMATFile(obj.simDataFile);
simIn = simIn.setModelParameter('StopTime', num2str(obj.fahrmanoeverObj.t_sim));
simIn = simulink.compiler.configureForDeployment(simIn);
obj.simOutput = sim(simIn);
end
% Output SimIn
simIn =
SimulationInput with properties:
ModelName: 'Bremsscheibensimulation_Simulation'
InitialState: [0×0 Simulink.op.ModelOperatingPoint]
ExternalInput: []
ModelParameters: [1×3 Simulink.Simulation.ModelParameter]
BlockParameters: [0×0 Simulink.Simulation.BlockParameter]
Variables: [1×120 Simulink.Simulation.Variable]
PreSimFcn: []
PostSimFcn: []
UserString: ''

채택된 답변

Christopher Wunder
Christopher Wunder 2022년 4월 7일
이동: Cris LaPierre 2022년 9월 9일
ok I figured it out by now, in case anyone has the same Problem:
I replaced "simIn = simulink.compiler.configureForDeployment(simIn)" by "simulink.compiler.configureForDeployment(simIn)". I don't know why it works, simulink.compiler.configureForDeployment seems to return the object, I can see the same output in the command window when initializing the SimulationInput object, but with a changed ModelParamter of course (and in different state it seems).
Anyway the examples on simulink.compiler.configureForDeployment in the documentation do also return the object, this might be a bit confusing.
  댓글 수: 2
William Stokes
William Stokes 2022년 9월 9일
이동: Cris LaPierre 2022년 9월 9일
I had this exact problem and your solution has fixed it (I think!). But very weird, because you are correct it does go against all the documentation which is suggesting the simin object is immutable and should be written back to itself...weird. But thanks still!
Giuseppe Avallone
Giuseppe Avallone 2024년 6월 19일
Hi,
I ran into the same identical problem and I really appreciate your answer.
The problem is that the instruction without assignation doesn't switch the model's acceleration mode (I mean, if the model is initially set to Normal it will stay in that mode). I have to manually switch to the Rapid Accelerator mode inside the .slx file.
However, the instruction
in = simulink.compiler.configureForDeployment(in);
consists of two statements:
in = in.setModelParameter('SimulationMode','Rapid');
in = in.setModelParameter('RapidAcceleratorUpToDateCheck','off');
If I comment the second line (or if I set it to 'on'), the error will be no longer displayed.
The weird thing is that I have used these instructions for other models and they work perfectly. It seems the problem does with the model, but I can't figure out where, since the error is too generic.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by