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

function out = modfunc(x,a:end)
What is your intention for the a:end clause ?
Dionysios
Dionysios 2023년 2월 6일
Thank you, I should have removed :end. Now it works perfectly.

댓글을 달려면 로그인하십시오.

답변 (2개)

John D'Errico
John D'Errico 2023년 2월 6일

0 개 추천

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

Dionysios
Dionysios 2023년 2월 6일
Thank you, I hadn't noticed it and now the code works.

댓글을 달려면 로그인하십시오.

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 2월 6일

0 개 추천

The corrected syntax of this is:
function out = modfunc(x,a);
out = a(1)*exp(a(2)*x);

댓글 수: 2

Dionysios
Dionysios 2023년 2월 6일
Thank you, it works like a charm
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 2월 6일
Most welcome!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2023년 2월 6일

댓글:

2023년 2월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by