我正在尝试使用matbugs界面,但遇到了一些问题并希望得到一些帮助。我是一个新的matlab用户,我正在努力解决matlab没有将某些文件写入“tmp”文件夹的问题。具体来说,代码写入data.txt文件和init_1.txt(当我只有一组初始值时),但不写任何其他文件。当我设置断点并运行代码时,会创建文件路径,但不会创建实际文件。当程序尝试读取bugs2mat函数中不存在的codaIndex.txt文件的“文件名”路径时,程序会给我一个错误。
这是代码
clear all
% Read in the data files
[SubID, Y, RewLos, T, N] = ReadInData();
% WinBUGS Parameters
% Total number of samples per chain = nburnin + nsamples*thin
nchains=3; % Number of MCMC chains
nburnin=2000; % Number of burn-in samples
nsamples=300; % Number of samples aften burn-in
thin = 50; % How often a sample is recorded (thin = 1 means every sample is recorded)
% Assign Matlab Variables to the Observed WinBUGS Nodes
%Data provided to BUGS are: RewLos[1:2, 1:T, 1:N], Y[1:N, 1:T], N, & T[i]
datastruct = struct('Y', Y, 'RewLos', RewLos,'T',T, 'N', N);
%Initialize Unobserved Variables
for i=1:nchains
S.muA = .5;
S.muW = .5;
S.muC = .2;
S.muG = .2;
S.lambdaA = 1;
S.lambdaW = 1;
S.lambdaC = 1;
S.lambdaG = 1;
S.a = unifrnd(0.4,0.6,N,1);
S.w = unifrnd(0.4,0.6,N,1);
S.c = unifrnd(0.1,0.3,N,1);
S.g = unifrnd(0.1,0.3,N,1);
init0(i) = S;
end
% Use WinBUGS to Sample
[samples, stats] = matbugs(datastruct, ...
fullfile(pwd, 'PVL_truncNormal.txt'), ...
'init', init0, ...
'nChains', nchains, ...
'view', 0, 'nburnin', nburnin, 'nsamples', nsamples, ...
'thin', thin, 'DICstatus', 0, 'refreshrate',100, ...
'monitorParams', {'a', 'w', 'c', 'g', 'muA', 'muW', 'muC', 'muG', 'sigmaA', 'sigmaW', 'sigmaC', 'sigmaG'}, ... % Samples to track
'Bugdir', 'E:/WinBUGS14');
% Save output from bugs
savefile = 'PVL_FLIGT_StatPG.mat';
save(savefile, 'samples', 'stats')