我正在使用 Simulink 框图中的 Matlab 的 2 级函数,将串行数据发送到 Arduino 板,该板必须移动机器人的 11 个伺服系统。我试图通过将输入和输出端口的分配矢量化到相应的数据来提高模拟的速度,但我没有成功。这是我要矢量化的代码:
function Outputs(block)
global S
global last_sent;
servo=cell(1,11);
str='Mover(';
for i=1:11 %Pretending to replace it by vector operation
servo{i}=num2str(fix(block.InputPort(i).Data));
str=[str servo{i} ','];
end
str=[str(1:end-1) ')'];
fprintf(S,'%s\n',str);
flushoutput(S);
pause(10e-3)
fprintf(S,'%s\n','Realim()');
servo_pos=eval(fgetl(S));
for i=1:11 %Pretending to replace it by vector operation
block.OutputPort(i).Data=servo_pos(i);
end
flushinput(S)
last_sent=[ '[' str(7:end-1) ']'];
所以,基本上,我想消除那些 for 循环并用矢量化操作替换它们。我尝试使用:
运算符来获取所有输入/输出端口,但我总是收到此错误:
K>> block.InputPort(:)
No method 'InputPort' with matching signature found for class
'Simulink.MSFcnRunTimeBlock'.
简而言之,有没有办法矢量化 for 循环?
提前致谢!查理