diff options
| author | ziejd2 | 2017-09-28 15:04:40 -0500 |
|---|---|---|
| committer | ziejd2 | 2017-09-28 15:04:40 -0500 |
| commit | 8070dc963753142bb86c4ed698d91fd623ed28e7 (patch) | |
| tree | d0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/KPMtools/cell2num.m | |
| parent | 7cc31810d53176e805532b2789955f4eedbce6bb (diff) | |
| download | BNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz | |
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
Diffstat (limited to 'sourcecodes/bnt-master/KPMtools/cell2num.m')
| -rw-r--r-- | sourcecodes/bnt-master/KPMtools/cell2num.m | 57 |
1 files changed, 57 insertions, 0 deletions
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]); + |
