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

13 visualizzazioni (ultimi 30 giorni)
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 Commento
Stephen23
Stephen23 il 19 Feb 2016
Modificato: Stephen23 il 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.

Accedi per commentare.

Risposta accettata

Stephen23
Stephen23 il 19 Feb 2016
Modificato: Stephen23 il 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 Commento
Antonio José Jiménez
Antonio José Jiménez il 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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by