필터 지우기
필터 지우기

Error: Function definitions are not permitted in this context

조회 수: 3 (최근 30일)
Mai Sakuragi
Mai Sakuragi 2020년 4월 14일
댓글: Mai Sakuragi 2020년 4월 14일
function s = myode_detuning(t, G, omega_e,omega_c, Omega, gamma, topt, tau_opt, tspan, gammafunc)
gammafunc = interp1(tspan,gammafunc,t); % Interpolate the data set (ts,gammafunc) at time t
s = [G(2) ; -omega_e^2 * G(1) + Omega^2 * G(3) - gammafunc * G(2) + sin(omega_c*t)*exp(-4*log(2)*(t-topt)^2/tau_opt^2); G(4) ; -omega_c^2 * G(3) + Omega^2 * G(1) - gamma * G(4)] ;
I run the code above on MATLAB R2016b to define function that's used in another MATLAB script (separate file).
tspan is defined in that another file.
However, I get errors below.
{Error: Function definitions are not permitted in this context.
}
{Undefined function or variable 'tspan'.
}
{Undefined function or variable 'G'.
}
When I run this code using MATLAB R2019a it works fine.
What do I need to fix in order to run this in R2016b?
The code above is saved in a (.m) file.
  댓글 수: 4
Adam Danz
Adam Danz 2020년 4월 14일
편집: Adam Danz 2020년 4월 14일
It doesn't look like a standard error message. I haven't seen an error message that appears in brackets. If the solution in my answer doesn't fix the problem, please attach the m-file.
Mai Sakuragi
Mai Sakuragi 2020년 4월 14일
I am runnnig the script using HPC, so it is a little different.
This is the screenshot. I get another error after adding "end".

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

답변 (1개)

Adam Danz
Adam Danz 2020년 4월 14일
편집: Adam Danz 2020년 4월 14일
Starting in r2016b, functions can be defined within scripts but they must end with the end keyword.
For more information:
  댓글 수: 4
Mai Sakuragi
Mai Sakuragi 2020년 4월 14일
So I'm using Unix HPC Cluster. I am not sure if it's Microsoft HPC.
Anyway, whenever I run the code it creates an error file and an output file, and if there is any error, error message appears in the error file. The first screenshot is the message that appears in the error file. The original script is in the m-file.
Mai Sakuragi
Mai Sakuragi 2020년 4월 14일
I really don't know what is causing the error but I need to get the result using HPC because the memory on my PC is too small and just can't handle the large size computation that I am doing. Does anyone have any idea why??

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

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by