- You try to use the function keyword at the command line. function cannot be used at the command line; the only kind of functions that can be defined at the command line are anonymous functions
- In R2015a or earlier, you try to use the function keyword in the same file as a script file, after the script. It did not become permitted to define a script in a function file until R2015b.
Function definitons are not permitted in this context.
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello,
I want to calculate a far field pressure for multiple surface displacements.
I am trying to use the following code :
function P = pression(u_r,xi)
% I have to define the global parameters but it doesn't change the error
s = 0 ;
cpt = 0;
for theta = 0:pas_a:2*pi
s = u_r(1)*xi(1)*besselj(0,k*pi*sin(theta));
for j = 2:1:55
s = u_r(j)*( xi(j)-xi(j-1) )*besselj(0,k*pi*sin(theta));
end
cpt = cpt+1;
P(cpt) = abs(rho*c*k/r*s);
end
end
u_r is the displacement(1x55), xi is the lenght along which the displecment is (1x55), P is the far field pressure (361,1)
As far as I know this calculation works well for a single u_r outside of a function. But I have a table of displacements (13x55) named U where the different dispplacements are; I want to calculate all the far field pressures and store them in a single table (361x13) so as to be able to plot all of them on a single graph.
I initially programmed this with 3 for loops; but this resulted in a very false pressure and most of the results where equal to 0 for some reason; so I quickly abandonned that idea.
So I thought of implementing a function to calculate the pressure but I can't seem to program it.
PS : I will then call this function in a for loop :
RES = zeros(361,13);
for k = 1:13
RES(:,k) = pression(U(:,k),xi);
end
Any help is appreciated!!
Thanks
댓글 수: 0
답변 (1개)
Walter Roberson
2021년 9월 1일
"Function definitions are not permitted in this context." occurs in any of the following circumstances:
And really, that is it.
You indicate you are using R2017a, so the second of those should not apply. The implication, by elimination, is that you tried to define a function at the command line.
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!