【发布时间】:2017-11-14 13:31:57
【问题描述】:
我是 MATLAB 新手,我无法让我的函数工作以将我的数据保存到 .mat 文件中。
输入:
-
一个结构,有 5 个字段:
-
data:19x1000x143 的 3D 矩阵 -
labels:1x143 矩阵,其中包含1或-1 -
subject_number:一个整数 -
sampling_rate:整数,500Hz -
channel_names: 1x19 矩阵,其中包含文本
-
name:文件名字符串clean:一个 1x143 的矩阵,其中包含1或0。
这个想法是只保存干净的数据,在干净的矩阵中标记为1。
If clean(i) is equal to 1:
save data(:,:,i) and labels(:,i)
这是我尝试在 save.m 文件中实现的代码:
function saving(EEG_struct, clean, name)
subject_number = EEG_struct.subject_number;
fs = EEG_struct.sampling_rate;
chan_names = EEG_struct.channel_names;
nb_epoch = size(EEG_struct.data, 3);
for j=1:nb_epoch
if clean(j) == 1
% Keep the epoch and label
data = cat(3, data, EEG_struct.data(:,:,j));
labels = cat(2, labels, EEG_struct.labels(:,j));
end
end
save(name, data, labels, subject_number, fs, chan_names)
如您所见,我想将数据保存为与EEG_struct 输入具有相同形状的结构。
此外,我想使用 parfor 而不是 for,但它给我带来了一个我不太明白的错误:
An UndefinedFunction error was thrown on the workers for 'data'. This might be because the file containing 'data' is not accessible on the workers. Use addAttachedFiles(pool, files) to specify the required files to be attached. See the documentation for 'parallel.Pool/addAttachedFiles' for more details. Caused by: Undefined function or variable 'data'.
感谢您的帮助!
【问题讨论】: