Unable to read .mat files from a folder

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by