multiple inputs for a function
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Giuseppe
le 2 Avr 2014
Réponse apportée : Mischa Kim
le 2 Avr 2014
this is my function
function ispal=palindrome(forward_string)
reverse_string = forward_string(end:-1:1);
ispal = all(forward_string == reverse_string);
return
end
how could i change this if i give multiple strings as forward_string i get multiple outputs wether or not it is a palindrome. e.g. input of {'dog', 'abba'}
0 commentaires
Réponse acceptée
Mischa Kim
le 2 Avr 2014
Giuseppe, you could use
function ispal = palindrome(forward_string)
for ii=1:numel(forward_string)
ispal{ii} = strcmp(forward_string{ii},fliplr(forward_string{ii}));
end
Alternatively, you could return ispal as a numeric array: ispal(ii).
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!