Unable to read .mat files from a folder

2 ビュー (過去 30 日間)
divya r
divya r 2012 年 6 月 17 日
I have multiple .mat files in the a folder. I want to read each of the files and compare its data with one of the file of the same folder.
In line 6 I expected the path of the .mat file to be displayed. What was expected is C:\Users\Toshiba\Desktop\friday work\1_1_1.mat, C:\Users\Toshiba\Desktop\friday work\1_1_2 and so on for each file, instead i got C:\Users\Toshiba\Desktop\friday work\. , C:\Users\Toshiba\Desktop\friday work\..
The code I used is:
f_s = 'C:\Users\Toshiba\Desktop\friday work\';
f_s_2 = 'C:\Users\Toshiba\Desktop\friday work\1_1_2.mat';
ss = dir(f_s);
for i = 1:1:size(ss, 1)
im_nm = strcat(f_s, ss(i).name);
disp(im_nm);
end
I am unable to read the .mat file in the folder

採用された回答

Walter Roberson
Walter Roberson 2012 年 6 月 17 日
Use
im_nm = fullfile(f_s, ss(i).name)
and keep in mind that when you dir() on a folder, you get everything in the folder, including all the directory links such as "." and ".." . To eliminate those
ss = dir(f_s);
ss([ss.isdir]) = [];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by