Simulation of SimuLink Block From Matlab Function (Errors)

Hey guys,
I am trying to run a simulatin of a simulink block model from matlab function, but whenever i tried to call it out, it produce multiple error msgs:
Caused by: Error using ==> Winter_Code_v3 at 313 Error evaluating 'InitFcn' callback of Battery block (mask) 'Batt_Model_Pack/Battery1/Model/Continuous/Saturation Dynamic'. Error in 'Batt_Model_Pack/Battery1/Model/Continuous/Saturation Dynamic': Initialization commands cannot be evaluated. Error using ==> Winter_Code_v3 at 313 Error in 'Batt_Model_Pack/Battery1/Model/Continuous/Saturation Dynamic': Initialization commands cannot be evaluated. Error using ==> Winter_Code_v3 at 313 Error evaluating parameter '(sort(reshape(round(NumBitsAllowFinal), prod(size(NumBitsAllowFinal)),1)))' in 'Batt_Model_Pack/Battery1/Model/Continuous/Saturation Dynamic/Data Type Propagation': Index exceeds matrix dimensions.
The command that i use to call out : sim('Batt_Model_Pack', timestep*60);
i did run it before but in a smaller section code and it works fine but when integrating with other parts it produces this error.
Anyone has encounter this error before and care to share>
Thanks, really appreciate yr help.

1 Comment

It seems there is an error evaluating the parameter of the block Batt_Model_Pack/Battery1/Model/Continuous/Saturation Dynamic. Perhaps one or more required variables have not been defined correctly in the workspace. Are all the variables used in the expression "(sort(reshape(round(NumBitsAllowFinal), prod(size(NumBitsAllowFinal)),1)))" defined in the base or model workspaces?
For easier debugging, I would recommend opening the model Batt_Model_Pack and attempt to run it directly (instead of from a MATLAB function). This will throw Simulink errors in a popup dialog that will highlight the blocks causing the error.

Sign in to comment.

Answers (2)

The error message says it all.
One of your blocks has a 'InitFcn' callback. The error happens when it tries to run that callback function. The particular line is
'(sort(reshape(round(NumBitsAllowFinal), prod(size(NumBitsAllowFinal)),1)))'
The error type is: Index exceeds matrix dimensions
Firs, try to load the model and run simulation manually without using the sim() command. Try to run the sort() command separately to see where is the error.
Thanks guys,
I have found out the problem for this, there is a clash of variable used in my code and the simulink model, variable called 'round', I think this causes the problem.
I have change it to another name and it works fine.
Thanks guys for the reply.

1 Comment

Thanks...
This was really helpful for me to solve the same issue which i have faced with the keyword 'size'.
I have used 'size' in my .m script which was a keyword in matlab.

Sign in to comment.

Categories

Find more on Simulink in Help Center and File Exchange

Asked:

on 27 Jun 2011

Edited:

on 6 Mar 2020

Community Treasure Hunt

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

Start Hunting!