Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the file name without Extension in matlab

I want to get the image file name without the Extension in MATLAB. I have Tried to use (fileparts )function as:

[pathstr, name, ext, versn] = fileparts(filename); 

in this function the (filename) must be with complete Path in order to get the file name without extension in the the variable (name).

when I have just the file name like ('D10_11.jpg'), I get the following Error :

"Input must be a row vector of characters"

Please, if their is another function to solve this problem

like image 471
zenab Avatar asked Dec 03 '10 16:12

zenab


2 Answers

From your error message, I guess that the input could be a cell array, rather than a char array.

Thus, instead of

[pathstr,name,ext] = fileparts(filename)

you'd have to write

[pathstr,name,ext] = fileparts(filename{1})
like image 154
Jonas Avatar answered Oct 10 '22 21:10

Jonas


This works fine for me:

>> filename = 'D10_11.jpg';
>> [pathstr,name,ext,versn] = fileparts(filename)

pathstr =

     ''

name =

D10_11

ext =

.jpg

versn =

     ''

You should check to make sure filename is actually what you think it is. The error suggests that it isn't just a row vector of characters like 'D10_11.jpg'.

like image 40
gnovice Avatar answered Oct 10 '22 21:10

gnovice