How to solve the 'StopFcn' error when the cause is "Vectors must be the same length."
Show older comments
I have got a simulation file for a grid-tie inverter, which I am going to leave its image below. When I run the simulation, I receive the following error:
Error evaluating 'StopFcn' callback of block_diagram 'DC2ACGRID2'.
Caused by:
Vectors must be the same length.
I cannot figure out what vectors are causing this trouble. Any help is very much appreciated.

17 Comments
Swarooph
on 25 Jul 2017
According to the error, the issue is not in the block diagram per se but the StopFcn callback that is calling some MATLAB commands. Assuming DC2ACGRID2 is your model name, at the MATLAB command prompt, execute the following command to see what this is:
get_param('DC2ACGRID2','StopFcn')
The output will be a call to a MATLAB m code file or a list of MATLAB commands. In the former case, put a breakpoint in the first line of this file, run the model and see that the breakpoint is activated. Then step through the code in the file to see which line errors out. In the latter case, replace the commands in StopFcn with a call to a new MATLAB m code file that contains those commands and then follow the breakpoint approach already discussed to find out the line number at which you see the issue.
sanjiv kumar
on 1 Aug 2019
"Error evaluating 'StopFcn' callback of block_diagram 'qpsk'.
Vectors must be the same length.'
I AM FACING THE SAME PROBLEM IN MY SIMULINK BLOCK, WHEN I WAS CALCILATING IN BER USING 'bertool' with simulink block.
Sorry , but i can't understand the solution,which is provided by "Sawroop".
Please explain same example,if it is possisble
Walter Roberson
on 1 Aug 2019
get_param('qpsk', 'StopFcn')
to see what code is being executed and show us.
wong jun yen
on 2 Jan 2020
>> get_param('qpsk','StopFcn')
ans =
0×0 empty char array
Akash Lonarkar
on 4 Feb 2020
>> get_param('test','StopFcn')
ans =
0×0 empty char array
Getting same issue, did anybody get the solution to this?
Walter Roberson
on 4 Feb 2020
Please attach your model, and indicate what steps are required to trigger the error message.
Akash Lonarkar
on 23 Feb 2020
Walter Roberson
on 23 Feb 2020
The model requires that a variable named EbNo exists. What value should that variable have ?
Walter Roberson
on 23 Feb 2020
I went through Akash Lonarkar's model step by step. The StopFcn had a call to
;bertool('stopped')
The ';' is useless there, but removing it does not make a difference.
The problem is that bertool() only expects to be called with parameters under controlled circumstances. Those circumstances include calling bertool() with the parameter 'simulationInit' followed by 6 parameters. One of the parameters is the name of a model, and it opens the model. One of those things that the initialization code does is set the StopFcn of the model to invoke bertool('stopped') . It thus appears that you have saved the resulting model but that you are not invoking it the same way that you initially invoked bertool to get it to work with the model at all. That step needs to be done.
Bhulok Aryal
on 6 May 2020
Can you please elaborate what steps you are talking. I tried to do but still stuck in same error
Walter Roberson
on 6 May 2020
set_param('test', 'StopFcn', '')
Now save your model.
The result will be something that makes no attempt to invoke bertool when you stop the model. You can invoke bertool yourself if you want to.
Idil Ünlü
on 5 Jan 2021
It didn't work for me. Is there any possible error source other than that?
Walter Roberson
on 5 Jan 2021
Is your StopFcn for your model showing up with a reference to bertool ?
Onyinyechukwu Obike
on 13 May 2021
yes
Walter Roberson
on 13 May 2021
set_param('YourModelNameGoesHere', 'StopFcn', '')
then save your model.
Lazar Dulovic
on 30 Jun 2022
Sudhir
on 14 Dec 2024
Moved: Walter Roberson
on 17 Dec 2025
Error evaluating 'StopFcn' callback of block_diagram 'StateflowOnramp'. Callback string is 'learning.simulink.modelCallbacks.stopFunction(gcs);'
Caused by:
- Invalid Simulink object handle
how to fix this issue ?
Answers (1)
Scout Patel
on 31 Mar 2021
2 votes
- Go to the "MODELING" tab on the simulink window.
- In the Center click on "Model Settings".
- Under Data Import/Export UNCHECK the box next to: "Single Simulation output:"
3 Comments
Abdul QAder
on 21 Jun 2021
Can be useful
Abdul QAder
on 21 Jun 2021
Good
Jehan Jayanetti
on 17 Dec 2025
I had this box unchecked and still received the same error message.
Categories
Find more on Simulink in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!