How do you write a filepath into a table?
3 ビュー (過去 30 日間)
古いコメントを表示
I have searched for some answer relevent to what I am asking and cannot find anything, so any help would be appreciated. I have a strange set of data, in that the filename of the .csv does not give all of the info of what is in the data, most of the info is located in the folder names. This is not an issue when dealing with a small amount, and I can look at it manually. However I have hundreds of filepaths. So my question is, is there a way to put the data in a table with information from the folder names in the table with it? for example if the path was something like
C:\Users\JY\Desktop\Weather\Monday\Overcast.csv
can I have a table that would show
[Weather,Monday,Overcast,"data_from_.csv" ]
thanks in advance for any help on this.
0 件のコメント
採用された回答
Voss
2022 年 3 月 4 日
file_names = { ...
'C:\Users\JY\Desktop\Weather\Monday\Overcast.csv'
'C:\Users\JY\Desktop\Weather\Tuesday\Sunny.csv' ...
};
% split the file names on '\' and '.' (you can use filesep() instead of '\'
% here):
new_names = cellfun(@(x)strsplit(x,{'\' '.'}),file_names,'UniformOutput',false);
new_names{:}
% Keep the last 4 parts (everything after "Desktop"):
file_info = cellfun(@(x)x(end-3:end),new_names,'UniformOutput',false);
file_info = vertcat(file_info{:})
% append the 'data_from_.' to the last column (containing 'csv'):
file_info(:,end) = strcat('data_from_.',file_info(:,end));
disp(file_info);
% convert to an array of strings if that's what you need to use:
file_info_str = string(file_info);
disp(file_info_str);
% or convert either one into a table:
t = array2table(file_info,'VariableNames',{'Type','Day','Category','file(?)'})
t = array2table(file_info_str,'VariableNames',{'Type','Day','Category','file(?)'})
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!