フィルターのクリア

Extracting name of multiple files to use in Plotting multiple graph

3 ビュー (過去 30 日間)
Amit
Amit 2013 年 7 月 23 日
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 Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by