- The function needs to be the main function in a function file (not a script file)
- The script file needs to create a function handle to the function
- The function file in which it is a local function needs to return a function handle to that local function, or
- The function needs to be a method of a class
how to access function from a different scipt?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
tyler hollings
le 4 Sep 2020
Commenté : tyler hollings
le 4 Sep 2020
i keep getting an error that says "Local function name must be different from the script name." when i try to call a funtion from a different script
i know my funtion works i just dont know how to call if from a different script
clear all
close all
create_array(10,5,1)
function create_array(N,M,row_orient)
if row_orient==1
for i=1:N
for j=1:M
if N==M
x(i,j)= N*(i-1)+j
elseif M-N >=1 | N-M >= 1
x(i,j)=M*(i-1)+j
end
end
end
elseif row_orient==0
for i=1:N
for j=1:M
if N==M
x(j,i)= N*(i-1)+j
elseif M-N >=1 | N-M >= 1
x(j,i)=M*(i-1)+j
end
end
end
end
end
0 commentaires
Réponse acceptée
Steven Lord
le 4 Sep 2020
That error message is correct. If you have a function inside a script file, the name of the function must not be the same as the name of the script. This is documented in the Note in the "Syntax for Function Definition" section on this documentation page.
As stated on this other documentation page functions in script files are not normally accessible outside that script file. If you want that function to be accessible one of the following must be true. [I don't think I missed any possibilities, but if I did these are the most common ways to make a function in a file accessible to the Command Window and other files.] The first is probably the easiest.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!