Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Help with saving files
2 ビュー (過去 30 日間)
古いコメントを表示
I need help with the following operation. I have a folder, let's call it 'folder1' (directory C:\Users\Desktop\folder1), where I have the following .dat files: tryA, tryA_0, tryA_1, tryA_2,...,tryA_n , tryB, tryB_0, tryB_1, tryB_2,...,tryB_n (n is an arbitrary integer). They all have same dimension MxN double . What I need is to create and save all the matrices tryAd=tryA-tryB, tryA_0d=tryA_0-tryB_0, tryA_1d=tryA_1-tryB_1,...,tryA_nd=tryA_n-tryB_n in the same folder, once I have loaded just the two files tryA and tryB . Of course they will be .dat files with same dimension MxN. There should be a way to recognize files starting with 'tryA' and 'tryB' and ending with '_0','_1' and so on. Can you please suggest me a code to do this operation, with the variables I have indicated? Thank you very much!
0 件のコメント
回答 (1 件)
Konstantinos Sofos
2015 年 3 月 19 日
編集済み: Konstantinos Sofos
2015 年 3 月 19 日
Hi,
I think that List folder contents and File name processing from directory listing would be a could start for you.
I use this method all the time (replace <folder> and expression string> accordingly, and you could change the directory search string to be more specific/general if required:
% Get list of *.dat files
fnames = dir(fullfile(<folder>, '*.dat'));
% Only keep the file names - I don't care about the other data
fnames = {fnames.name}.'; % I like to ensure all vectors are columns
% Get indices of file names matching regular expression
FIND = @(str) cellfun(@(c) ~isempty(c), regexp(fnames, str, 'once'));
% Load data
fnames_subset = fnames(FIND(<regular expression string>));
Regards
2 件のコメント
Konstantinos Sofos
2015 年 3 月 19 日
編集済み: Konstantinos Sofos
2015 年 3 月 19 日
replace folder with C:\Users\Desktop\folder1 and expression string with '_1' just as an example. Then fnames_subset contains the files that you want first to load and then to substruct. If for example you set expression string with 'tryA' you will have all tryA*.dat files into fnames_subset.
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!