Error with writing a function

조회 수: 4 (최근 30일)
galben
galben 2022년 11월 2일
답변: Walter Roberson 2022년 11월 2일
function span(v, c)
A = [];
n = length(A);
for i=1:n
u=c{i};
u= u';
A = [A u(:)];
end
v= v';
v=v(:);
if rank(A) == rank([A v])
disp('Given vector is in the span.')
else
disp('Given vector is not in the span.')
end
All functions in a script must be closed with an 'end'.
I don't understand this response...thanks

답변 (3개)

Fangjun Jiang
Fangjun Jiang 2022년 11월 2일
편집: Fangjun Jiang 2022년 11월 2일
You must have included this in your script. This is not all of your code.
The direct solution for this is to add an "end" line at the end, to mark the "end" of the function span(v, c)

Steven Lord
Steven Lord 2022년 11월 2일
If you're writing a function inside a function file and any function in your function file ends with an end then every function in your function file must end with an end.
If you're writing a function inside a script file that function must end with an end.

Walter Roberson
Walter Roberson 2022년 11월 2일
The existing end on the last line of your code is the end matching the if statement. You need an additional end statement matching up to the function line.

카테고리

Help CenterFile Exchange에서 Adding custom doc에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by