Generic example of using Classic BUGS and WinBUGS with Matlab
First create appropriate script file and model file.
Then create data file
mat2bugs('stacks_dat.txt','Y',d(:,1),'x',d(:,2:end),'p',p,'N',n);
init file
mat2bugs('stacks_in.txt','beta0',10,'beta',[0 0 0],'tau',0.1);
call OpenBUGS (in Linux)
[s,w]=unix(['/proj/ave/OpenBUGS/LinBUGS < stacks_scro.txt']);or Classic BUGS (in Linux)
unix(['/proj/ave/bugs/backbugs stacks.bmd']);or WinBUGS (in Linux)
unix(['wine /proj/ave/c/WinBUGS/WinBUGS14.exe /PAR "Y:/cv_vs_dic/stacks/WinBUGS/stacks_scr.txt" 2> /dev/null' ]);Leming Qu reported that following works in Windows (replace <PATH> with real path)
dos('<PATH>\WinBUGS14 /PAR <PATH>\script.txt')
and read results to Matlab
S=bugs2mat('bugsIndex.txt','bugs1.txt');
Note that all different versions of BUGS use slightly different script syntax, and the script files sent to different versions have to be modified accordingly.

