我在读取文件中的值时遇到问题并将其放在Set_param函数中,这将改变SIMULINK模型参数。这是我的代码,在这里我从txt文件中获取A的值,但我想将A放在Set_param中。当simulink打开时,它显示A不是模型中A的值。
open_system('Transient.slx') %this will open the simulink model
% get a value from txt file and put it in variable A
A= dlmread('C:\xampp\htdocs\RCE\MATLAB\FYP_expirement\SpeedControl\exp_value.txt');
% here when i put the variable A the function does not accept it
set_param('Transient/Gain','Gain','A')
我尝试A没有单引号也给出错误。
set_param('Transient/Gain','Gain', A)
我怎么能在这个函数中插入一个变量?或者还有其他解决方案吗?
非常感谢,我找到了一种方法使它成功。似乎set_param只接受字符。所以在获得值之后我应该将它转换为字符串,如下所示:
A= dlmread('C:\xampp\htdocs\RCE\MATLAB\FYP_expirement\SpeedControl\exp_value.txt');
s = num2str(A)
set_param('Transient/Gain','Gain', s)
然后,当我在函数中插入s时,我不必使用引号。