How to select the first letter of every word

8 views (last 30 days)
I have no idea how I would go about doing this
Input: I like eating pizza Output: Ilep

Accepted Answer

Mohammad Abouali
Mohammad Abouali on 5 Dec 2015
Edited: Mohammad Abouali on 5 Dec 2015
str='I like eating pizza';
str2=cellfun(@(c) c(1),strsplit(str))
  6 Comments
Krish Desai
Krish Desai on 10 Dec 2015
Also how would I be able to eliminate extra spaces? For instance if the input was ' I like eating pizza'?
Krish Desai
Krish Desai on 10 Dec 2015
Function strtrim to fix this problem.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!