I have a piece of code that works perfectly when run from the command line, but when it is run inside of a Matlab function block in my Simulink simulation, I get a matrix dimensioning error.
Using the debugger, I have figured out that the for-loop is behaving differently from how I expect and I'm not sure how to fix it without major re-writes to someone else's code.
Here is the snippet of code that is causing problems.
for k=input
idx=4+2*(i-1)+1;
yhat=yhat+th(idx)*cos(k.*(2.*pi.*60.*t+th(1).*t))+th(idx+1)*sin(k*(2*pi*60*t+th(1)*t));
end
Normally, k would take on each value from 2 to 13 and this would run as one would expect a for loop to run. For some reason, when I set a breakpoint on the yhat
line, I am finding that k is the vector [2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13]
, which is the transpose of what I expect input
to be. Does anyone know what is going on that would make this code run differently in the Matlab Function block or how to fix it?