Extracting name of multiple files to use in Plotting multiple graph

1 次查看(过去 30 天)
I am creating a structure using the dir function , for all the text file present in a directory _text_files=dir(C:\Users\Desktop\.txt) (wild card star * is there before txt) _ ,now the structure text_files is having the names with the extension of all the text files inside the field 'name' of the sub-structures of text_files.
now i want the file names to be stored in a variable which i want to use as a label in plotting a graph for this i was trying to use the fileparts function , but the problem is that filespart function only accepts a file path as input argument thats what i know till now i can manually type the path and get the file name but i want to write a code that has to run iteratively , so i am avoiding this what i am doing is , i tried using the string concatenation function strcat to get the complete path as filepath=strcat('c:\Users\',text_files(1,1)) , and then using the fileparts function as [file_path file_name file_ext]=fileparts(filepath) , but it is not working , how can i do this.
Regards, Amit

回答(1 个)

Jan
Jan 2013-7-23
text_files = dir('C:\Users\Desktop\*.txt');
text_names = {test_files.name};
n = numel(text_names);
name = cell(1, n);
for k = 1:n
[dummy, name{k}] = fileparts(text_names{k});
end

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by