invalid use of operator

5 visualizaciones (últimos 30 días)
Dionysios
Dionysios el 6 de Feb. de 2023
Comentada: Sulaymon Eshkabilov el 6 de Feb. de 2023
I am trying to create an exponential function and then use the data for another script. To be more specific, I have a script file with an exponential function, but every single time I run the code I get the message: File: modfunc.m Line: 1 Column: 27
Invalid use of operator.
Here is the code:
function out = modfunc(x,a:end);
out = a(1)*exp(a(2)*x);
|x| representing time and |a| vector a with two values representing the coefficients.
  2 comentarios
Walter Roberson
Walter Roberson el 6 de Feb. de 2023
function out = modfunc(x,a:end)
What is your intention for the a:end clause ?
Dionysios
Dionysios el 6 de Feb. de 2023
Thank you, I should have removed :end. Now it works perfectly.

Iniciar sesión para comentar.

Respuestas (2)

John D'Errico
John D'Errico el 6 de Feb. de 2023
Looks great. Except, what you have written is not valid MATLAB syntax.
Why do you think you needed to include the :end in there? a is a vector of length 2. No problem.
function out = modfunc(x,a);
out = a(1)*exp(a(2)*x);
  1 comentario
Dionysios
Dionysios el 6 de Feb. de 2023
Thank you, I hadn't noticed it and now the code works.

Iniciar sesión para comentar.


Sulaymon Eshkabilov
Sulaymon Eshkabilov el 6 de Feb. de 2023
The corrected syntax of this is:
function out = modfunc(x,a);
out = a(1)*exp(a(2)*x);
  2 comentarios
Dionysios
Dionysios el 6 de Feb. de 2023
Thank you, it works like a charm
Sulaymon Eshkabilov
Sulaymon Eshkabilov el 6 de Feb. de 2023
Most welcome!

Iniciar sesión para comentar.

Categorías

Más información sobre Scope Variables and Generate Names en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by