# Errors occurred during parsing of MATLAB function

14 views (last 30 days)
Commented: Walter Roberson on 7 Mar 2022
I am trying to change the phase angle of the three phase source during simulation time. For this I intend on using a function block. Can you validate whether the application is correct. I am getting an error. I am not sure whether I am using the simulation time correctly. And do I need to add a line in matlab main script too?
I have used the following code in Matlab function block
function fcn(t)
coder.extrinsic('set_param');
coder.extrinsic('num2str');
phase=get_param('threebus/Three-Phase Source', 'PhaseAngle');
if (t>=5) && (t<=6);
phase2 = phase+1;
set_param('threebus/Three-Phase Source', 'PhaseAngle', num2str(phase2)); % write the name of your simulink model/block name
else
phase=0;
end
Walter Roberson on 7 Mar 2022
With the logic I proposed, you would not have any set/get at all.
But in any case: the set_param very likely (but not completely certainly) requires that you send it a character vector.
I am not clear at the moment as to whether the get_param is going to return a character vector or a numeric value.
If it returns a character vector then str2double() of that would be fine, and adding a number to the result would be fine, but you would have to num2str() or equivalent for the set_param() call.
... But as I said,you should not need that code at all. Do not change the properties of PhaseAngle, just add the appropriate correction to it before using the value.
The logic you drew would be plausible if ph_new were threebus/Three-Phase Source/PhaseAngle . You could use a GoTo if you are inside the same subsystem. You could use a GoTo in theory between subsystems, but that is typically not a good idea: better would be to have the value as an OutPort and connect the port as appropriate.

### Categories

Find more on Sources in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by