开发者

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 开发者_Python百科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


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})


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'.


Sorry for the super late answer :(, but I was facing the same problem. When I was searching for the answer I got the same question asked by someone else. There is no problem with the query you have written, only problem I see here is you are missing the format of the filename location.

filename = 'C:\Users\Public\myfile.csv';

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

Output is

pathstr =
C:\Users\Public
name =
myfile
ext =
.csv
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜