从子文件夹加载 .dat 文件

Loading .dat files from sub folders

我有以下代码; clear clc for n = 1:20 foldername = sprintf('G:\Protable Hard Drive\PHD Hard Drive\Experimental Data\Bulkrename Trial\TSR7.85\Center Left P%d\0.66D', n) dir(foldername) datfiles = dir(fullfile('.', 'foldername', '*.dat')) end

从这里我可以访问子文件夹 0.66D,它位于名为 Center Left P%d 的父文件夹中,%d 的范围从 1 到 20。使用 dir 命令我可以清楚地看到文件命令窗口中列出的每个子文件夹; `文件夹名=

G:\Protable Hard Drive\PHD Hard Drive\Experimental Data\Bulkrename Trial\TSR7.85\Center Left P1[=49=].66D

。 0_66D.R0027 0_66D.S0017 0_66D.T0007 0_66D.T0035 0_66D.V0025 POINT775.dat
.. 0_66D.R0028 0_66D.S0018 0_66D.T0008 0_66D.T0036 0_66D.V0026 POINT776.dat
0_66D.R0001 0_66D.R0029 0_66D.S0019 0_66D.T0009 0_66D.T0037 0_66D.V0027 POINT777.dat
0_66D.R0002 0_66D.R0030 0_66D.S0020 0_66D.T0010 0_66D.T0038 0_66D.V0028 POINT778.dat
0_66D.R0003 0_66D.R0031 0_66D.S0021 0_66D.T0011 0_66D.V0001 0_66D.V0029 POINT779.dat
0_66D.R0004 0_66D.R0032 0_66D.S0022 0_66D.T0012 0_66D.V0002 0_66D.V0030 POINT780.dat
0_66D.R0005 0_66D.R0033 0_66D.S0023 0_66D.T0013 0_66D.V0003 0_66D.V0031 POINT781.dat
0_66D.R0006 0_66D.R0034 0_66D.S0024 0_66D.T0014 0_66D.V0004 0_66D.V0032 POINT782.dat
0_66D.R0007 0_66D.R0035 0_66D.S0025 0_66D.T0015 0_66D.V0005 0_66D.V0033 POINT783.dat
0_66D.R0008 0_66D.R0036 0_66D.S0026 0_66D.T0016 0_66D.V0006 0_66D.V0034 POINT784.dat
0_66D.R0009 0_66D.R0037 0_66D.S0027 0_66D.T0017 0_66D.V0007 0_66D.V0035 POINT785.dat
0_66D.R0010 0_66D.R0038 0_66D.S0028 0_66D.T0018 0_66D.V0008 0_66D.V0036 POINT786.dat
0_66D.R0011 0_66D.S0001 0_66D.S0029 0_66D.T0019 0_66D.V0009 0_66D.V0037 POINT787.dat
0_66D.R0012 0_66D.S0002 0_66D.S0030 0_66D.T0020 0_66D.V0010 0_66D.V0038 POINT788.dat
0_66D.R0013 0_66D.S0003 0_66D.S0031 0_66D.T0021 0_66D.V0011 POINT761.dat POINT789.dat
0_66D.R0014 0_66D.S0004 0_66D.S0032 0_66D.T0022 0_66D.V0012 POINT762.dat POINT790.dat
0_66D.R0015 0_66D.S0005 0_66D.S0033 0_66D.T0023 0_66D.V0013 POINT763.dat POINT791.dat
0_66D.R0016 0_66D.S0006 0_66D.S0034 0_66D.T0024 0_66D.V0014 POINT764.dat POINT792.dat
0_66D.R0017 0_66D.S0007 0_66D.S0035 0_66D.T0025 0_66D.V0015 POINT765.dat POINT793.dat
0_66D.R0018 0_66D.S0008 0_66D.S0036 0_66D.T0026 0_66D.V0016 POINT766.dat POINT794.dat
0_66D.R0019 0_66D.S0009 0_66D.S0037 0_66D.T0027 0_66D.V0017 POINT767.dat POINT795.dat
0_66D.R0020 0_66D.S0010 0_66D.S0038 0_66D.T0028 0_66D.V0018 POINT768.dat POINT796.dat
0_66D.R0021 0_66D.S0011 0_66D.T0001 0_66D.T0029 0_66D.V0019 POINT769.dat POINT797.dat
0_66D.R0022 0_66D.S0012 0_66D.T0002 0_66D.T0030 0_66D.V0020 POINT770.dat POINT798.dat
0_66D.R0023 0_66D.S0013 0_66D.T0003 0_66D.T0031 0_66D.V0021 POINT771.dat master.bak
0_66D.R0024 0_66D.S0014 0_66D.T0004 0_66D.T0032 0_66D.V0022 POINT772.dat vtmp.000
0_66D.R0025 0_66D.S0015 0_66D.T0005 0_66D.T0033 0_66D.V0023 POINT773.dat vtmp.001
0_66D.R0026 0_66D.S0016 0_66D.T0006 0_66D.T0034 0_66D.V0024 POINT774.dat `

然而,当我尝试将每个子文件夹中的所有 .dat 文件加载到我的工作区时,出现以下错误; `数据文件 =

具有字段的 0x1 结构数组:

name
date
bytes
isdir
datenum`

任何人都可以向我解释为什么会这样吗? 问候, 杰瑞

请检查fullfile('.', 'foldername', '*.dat')的输出,.\foldername\*.dat中没有文件。 foldername是变量,不要用引号,前导的.与绝对路径组合时没有意义。