is there a way to define the source workspace in Matlab for 'linearize' when used within a function?
Here a short minimal working example:
clear all
sys = 'watertank';
open(sys)
sys_io(1) = linio('watertank/PID Controller',1,'input');
sys_io(2) = linio('watertank/Water-Tank System',1,'openoutput');
linsys = GetLinsys(sys,sys_io);
disp(linsys.a)
The function is:
function linsys = GetLinsys(sys,sys_io)
A = 10;
linsys = linearize(sys,sys_io);
end
The output is
-0.0500
since the linearize
uses the inital value of A in the 'base' workspace (A=20) and not the value in the 'current' workspace (A=10).
However, I would expect
-0.1000
This is obtained if the code of the function is included in the script:
clear all
sys = 'watertank';
open(sys)
sys_io(1) = linio('watertank/PID Controller',1,'input');
sys_io(2) = linio('watertank/Water-Tank System',1,'openoutput');
A = 10;
linsys = linearize(sys,sys_io);
disp(linsys.a)
Thus, the question is: How can I get the same result using the function?
For the sim
command, this can be done via the options:
options = simset('SrcWorkspace','current');
sim('modelname',[],options)
see here. However, I couldn't find something similar in the linearization options.
Thanks a lot for any help or suggestion!