Undefined function 'times' for input arguments of type 'struct'.

13 views (last 30 days)
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.
  1 Comment
Stephen23
Stephen23 on 19 Feb 2016
Edited: Stephen23 on 19 Feb 2016
Please show make a comment and show us the complete error message. This means all of the red text.
You also need to show us how you are calling your functions, because we cannot read your mind.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 19 Feb 2016
Edited: Stephen23 on 19 Feb 2016
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!
  1 Comment
Antonio José Jiménez
Antonio José Jiménez on 22 Feb 2016
The file "RK.m" call to maqi.m. When I run it, the wrong appear in the workspace. They are the only files I have.
Thank you for your advice.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!