Effacer les filtres
Effacer les filtres

Function is throwing error when calling it in different script

42 vues (au cours des 30 derniers jours)
OmartheEngineer
OmartheEngineer le 2 Juil 2024 à 21:05
Commenté : Les Beckham le 2 Juil 2024 à 21:44
I have a function, attached, that I am calling in different script. Everytime I call it I get the error
"Local function name must be different from the script name"
I was under the impression both the script and function must have the same name? Atleast how i have my other functions working. Nonetheless, even when I resave it with a different name I cant get it to work

Réponses (1)

Les Beckham
Les Beckham le 2 Juil 2024 à 21:18
Modifié(e) : Les Beckham le 2 Juil 2024 à 21:44
You have a non-comment line before the function definition starts. Thus, Matlab thinks that this is a script. Make the first line a comment, and this problem should go away. Note that the code analyzer in the editor flags this issue with red squiggles under the function name and also flags some other issues with orange squiggles. You need to fix those as well. Specifically, you can't use == to compare a character vector. You either need to use a string scalar (with double quotes, if the Master parameter that you pass in is also a string scalar) or use the strcmp function.
GtDis2wL
%Created: 7/1/24
%Latest revision
function [wl,Deg] = GtDis2wL(Master,Dist,Peak)
if Master == '2135'
rExt=100;
alpha=2.627499; %deg
beta405=-32.0725; %deg
WL=6010; %nm
G=1197.9*10^-6; %g/nm
names=-1;
DistOfst=Peak-Dist;
DegOfst=atand(DistOfst/rExt);%deg
Deg=DegOfst+beta405;%deg
wl=(-1/G)*(sind(alpha)+sind(Deg));
else
print('Hello')
end
end
  2 commentaires
OmartheEngineer
OmartheEngineer le 2 Juil 2024 à 21:23
Modifié(e) : OmartheEngineer le 2 Juil 2024 à 21:27
Loool I feel so dumb. Thats what happens when youve been starting at a screen for hours... I commpletely missed it. Can you edit your answer to remove the name at the top please? Ill select you as my answer. Thanks
Les Beckham
Les Beckham le 2 Juil 2024 à 21:44
You are quite welcome. I've edited the answer.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by