我在从文件中读取值并将其放入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)
如何在此函数中插入变量?还是有其他解决方案?
答案 0 :(得分:0)
非常感谢您,我找到了一种使其有效的方法。似乎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时,不必使用引号。