Vote count:
0
I'm working with the Matlab's level 2 Functions within a Simulink block diagram to send serial data to an Arduino Board, which has to move 11 servos of a robot. I'm trying to improve the speed of the Simulation by vectorizing the assignment of the input and output ports to the corresponding data but I haven't have success. Here is the code that I'd like to vectorize:
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) ']'];
So, basically, I want to eliminate those for loops and replace them by vectorized operations. I've tried to use the :
operator to get all the the input/output ports but I always get this error:
K>> block.InputPort(:)
No method 'InputPort' with matching signature found for class
'Simulink.MSFcnRunTimeBlock'.
In short, is there a way to vectorize the for loops?
Thanks in advance! Charlie
asked 41 secs ago
Aucun commentaire:
Enregistrer un commentaire