필터 지우기
필터 지우기

Why do get error in line 10: Function Keyword is invalid here. This might cause later messages about end.

조회 수: 21 (최근 30일)
I am trying to create a recursive function with output a Cell (1xN)that will consists of N matrixes. Each matrix represent a combination between the elements of X1 input Cell. I dont understand why i get this error.. Thank you for any help in advance!
VARMTD=[1,1/3,1/5];
VARMT1=(1:156);
ERLANGVARCELL={};
ERLANGVARCELL{1}=VARMT;
ERLANGVARCELL{2}=VARMTD;
A=zeros(1,length(ERLANGVARCELL));
ADR=zeros(1,length(ERLANGVARCELL));
Q=myfun(ERLANGVARCELL,A,ADR);
function G= myfun(x1,x4,ADR)
b=find(x4>0);
if length(b)==length(x1)
x3=length(b);
else
x3=length(b)+1;
end
i=ADR(x3)+1;
if i<=length(x1{x3})
x4(x3)=x1{x3}(i);
ADR(x3)=ADR(x3)+1;
end
for s=length(x1):1
hlp=1;
if s==length(x1);
hlp=1;
else
for b=(s+1):length(x1)
hlp=length(x1{b})*hlp;
end
end
if ADR(s)==length(x1{s})*hlp
ADR(s)=0;
x4(s-1)=0;
end
end
G=[x4,myfun(x1,x4,ADR)];
end

채택된 답변

David Young
David Young 2015년 7월 6일
You can't mix a script and a function in the same m-file. If an m-file contains a function, the first line of code in the file must start with the word function (or classdef). The message is because function is an invalid keyword if it is in a file that has started some other way.
The solution is to put your function into a file by itself. The file should be called myfun.m

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by