How can ı call this void function from another file.I could not do it

function [] = palindromeprime(n)
reverse = 0;
new = n;
prime = n;
x = true;
while new > 0
t = mod(new,10);
reverse = 10*reverse+t;
new= (new-t)/10;
end
for i = 2:(prime - 1)
if mod(prime,i) == 0
x = false;
break;
end
end
if(n == reverse && x == true)
fprintf("This is a palindrome prime number");
else
fprintf("This is NOT a palindrome prime number");
end

3 commentaires

dpb
dpb le 4 Mai 2020
Modifié(e) : dpb le 4 Mai 2020
Just like any other MATLAB function or script...
palindromeprime
from the command line or in a script.
What did you try and what was the error message returned?
It does have to be in a directory on MATLABPATH or in your current working directory to be found...
palindromeprime(101);
I CALLED FUNCTİON LİKE ABOVE FROM ANOTHER FİLE
HERE IS THE ERROR MESSAGE;
error: 'palindromeprime' undefined near line 2 column 1
error: called from
calis at line 2 column 1
By the way,ı create a file with functions name also
Well, that indicates that the function file name either is misspelled maybe or that the location for it is not in either the working directory or on the MATLABPATH.
What does
which -all palindromeprime
return from the location from which you run the other function?
We can't see that function -- does it, by any chance, change the working directory inside it in order to find some data files? Something like that can break it because move away from the location where the m-file is located.
Without all the information in context, all we can do is guess...

Connectez-vous pour commenter.

Réponses (0)

Commenté :

dpb
le 4 Mai 2020

Community Treasure Hunt

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

Start Hunting!

Translated by