From 8070dc963753142bb86c4ed698d91fd623ed28e7 Mon Sep 17 00:00:00 2001 From: ziejd2 Date: Thu, 28 Sep 2017 15:04:40 -0500 Subject: BNW using Octave instead of Matlab. This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning. I am calling this BNW_1.02. It can be accessed at: compbio.uthsc.edu/BNW_1.02 --- sourcecodes/bnt-master/KPMtools/cell2num.m | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 sourcecodes/bnt-master/KPMtools/cell2num.m (limited to 'sourcecodes/bnt-master/KPMtools/cell2num.m') diff --git a/sourcecodes/bnt-master/KPMtools/cell2num.m b/sourcecodes/bnt-master/KPMtools/cell2num.m new file mode 100644 index 00000000..ffd25ce9 --- /dev/null +++ b/sourcecodes/bnt-master/KPMtools/cell2num.m @@ -0,0 +1,57 @@ +function N = cell2num(C) +% CELL2NUM Convert a 2D cell array to a 2D numeric array +% N = cell2num(C) +% If the cells contain column vectors, they must have the same number of rows in each row of C. +% Each column will be concatenated. +% +% Example 1: +% C = num2cell(rand(2,2)) +% [0.4565] [0.8214] +% [0.0185] [0.4447] +% N = cell2num(C) +% 0.4565 0.8214 +% 0.0185 0.4447 +% +% Example 2: +% C = cell(2, 3); +% for i=1:2 +% for j=1:3 +% C{i,j} = rand(i, 1); +% end +% end +% C = +% [ 0.8998] [ 0.8216] [ 0.6449] +% [2x1 double] [2x1 double] [2x1 double] +% C{2,1} = +% 0.8180 +% 0.6602 +% N=cell2num(C) +% 0.8998 0.8216 0.6449 +% 0.8180 0.3420 0.3412 +% 0.6602 0.2897 0.5341 + + +% error('use cell2mat in matlab 7') + + +if isempty(C) + N = []; + return; +end + +if any(cellfun('isempty', C)) %any(isemptycell(C)) + error('can''t convert cell array with empty cells to matrix') +end + +[nrows ncols] = size(C); +%N = reshape(cat(1, C{:}), [nrows ncols]); % this only works if C only contains scalars +r = 0; +for i=1:nrows + r = r + size(C{i,1}, 1); +end +c = 0; +for j=1:ncols + c = c + size(C{1,j}, 2); +end +N = reshape(cat(1, C{:}), [r c]); + -- cgit 1.4.1