Error with writing a function
Afficher commentaires plus anciens
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
Réponses (3)
Fangjun Jiang
le 2 Nov 2022
Modifié(e) : Fangjun Jiang
le 2 Nov 2022
0 votes
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
le 2 Nov 2022
0 votes
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
le 2 Nov 2022
0 votes
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.
Catégories
En savoir plus sur Adding custom doc dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!