Mahesh Gupta
Mahesh Gupta

Reputation: 2748

File Extension in Matlab

Is there any way to get extension of a file from its filename ?? The only algo I could develop to do the above task is to find last '.' and rest all string to end..

But not too sure how to get index of final '.' from the given string..

Any new idea or suggestion for the same ??

I'm actually trying to develop a filter which only does processing on all image files rather than other non image file... Is there any other way of doing the same using any inbuilt function ???

Upvotes: 2

Views: 5635

Answers (2)

Chris Turner
Chris Turner

Reputation: 109

You can use the regexp function with the split parameter

output = regexp(your_string, '\.', 'split')

The output is a cell array that you can pull the value you want out of.

http://www.mathworks.com/help/techdoc/ref/regexp.html

Upvotes: 0

Miebster
Miebster

Reputation: 2404

Use the built in function "fileparts".

Upvotes: 8

Related Questions