indexing string in function
Mostra commenti meno recenti
I have a function that i want to return the first and last word from a string. so for example firstAndLast('matlab') should give me (m,b), however i am only able to get the first letter from this function?
function [first,last] = firstAndLast(instring)
first=instring(1);
last=instring(length(instring));
end
6 Commenti
Your question is not clear: you write that you "want to return the first and last word from a string", but then your example seems to return the first and last letters: "firstAndLast('matlab') should give me (m,b)"
Which do you really want: the letters (like your example), or the words (like your explanation) ?
Ian Tee
il 5 Mag 2016
Stephen23
il 5 Mag 2016
What does "extract the first and last input of the string" mean ?
Do you want the first and last letters, or words ?
Ian Tee
il 5 Mag 2016
Ian Tee
il 5 Mag 2016
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Characters and Strings in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!