I am getting the error "Variable y must be of data type char. It is currently of type double."
34 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am getting the error "Variable y must be of data type char. It is currently of type double. Function should return with a character vector conataining only the email address." I'm not sure how to fix it please help.
function result = extractemail(input)
text = regexp(input,'[a-zA-Z0-9_.-]+@[a-zA-Z0-9_-]+.[a-z]+');
email = regexp(input,'[a-zA-Z0-9_.-]+@[a-zA-Z0-9_-]+.[a-z]+','match');
if(numel(text)==1)
result = char(email)
else
result = []
end
end
CODE TO CALL FUNCTION
result = extractemail('My email address is: raymond.kim@usc.edu so please email me');
OUTPUT
result =
'raymond.kim@usc.edu'
0 commentaires
Réponses (1)
Stephen23
le 21 Avr 2022
Modifié(e) : Stephen23
le 21 Avr 2022
extractemail('My email address is: raymond.kim@usc.edu so please email me')
extractemail('There is no email here')
function txt = extractemail(input)
rgx = '[a-zA-Z0-9_.-]+@[a-zA-Z0-9_-]+.[a-z]+';
txt = regexp(input,rgx,'match','once');
end
Note that defining a regular expression to match valid email adresses is not trivial (or perhaps solvable):
0 commentaires
Voir également
Catégories
En savoir plus sur String 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!