MATLAB: Undefined function ‘times’ for input arguments of type ‘struct’.

structtimes

Good afternoon!
I´m solving a ODE45 (RK.m) and I want to introduce in the function "maqi.m" an inlet variable called "SOC_1" because its necessary to solve the code. If I do it, Matlab returns me "Undefined function 'times' for input arguments of type 'struct' "
Where is the wrong?
Next attached the files.
Thank you so much.

Best Answer

There is nothing wrong with the variable SOC_1 inside maqi.m: every instance performs some numeric operation. The problem is that you are calling maqi with a structure for that input variable, whereas it should be numeric.
But because none of your supplied files actually call maqi, it is difficult to give much more advice than this. You need to show us exactly how you are calling maqi, and also provide us with the complete error message.
It is also quite possible that you are using the incorrect outputs from your Parametros function: it returns almost fifty individual output arguments! OUCH! This is an extremely buggy way to write code, because it is quite likely that one (accidentally) missing output argument means the other variables are allocated to different variable names than you think they have been. The simplest solution is to avoid using lots of output arguments and put all of those arguments into one simple structure:
function params = Parametros()
params.D = 1;
params.S = 2;
params.rc = [4,5m6];
end
then you only need to call Parametros like this:
S = Parametros();
and use them like this:
S.rc
S.D
then all of your parameters are passed easily without putting fifity individual arguments. Buggy programs come by design, and it is your job as the designer to make them less buggy by using good design!