Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/fn_numstruct2numcell_nummatrix.m

raw
1 function [uniform_cell, uniform_matrix3D, names_fields] = fn_numstruct2numcell_nummatrix(uniform_ps)
2 %[uniform_cell, uniform_matrix3D, names_fields] = fn_numstruct2numcell_nummatrix(uniform_ps)
3 %
4 % Inputs:
5 % uniform_ps: a structure where each field has the same nrows-by-ncols matrix. This function does NOT work
6 % if each field has different data types.
7 % Outputs:
8 % uniform_cell: nfields cells where each cell has a nrows-by-ncols matrix.
9 % uniform_matrix3D: 3-D array: nrows-by-ncols-by-nfields
10 %
11 % Copyright (C) 1997-2012 Tao Zha
12 %
13 % This free software: you can redistribute it and/or modify
14 % it under the terms of the GNU General Public License as published by
15 % the Free Software Foundation, either version 3 of the License, or
16 % (at your option) any later version.
17 %
18 % It is distributed in the hope that it will be useful,
19 % but WITHOUT ANY WARRANTY; without even the implied warranty of
20 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 % GNU General Public License for more details.
22 %
23 % If you did not received a copy of the GNU General Public License
24 % with this software, see <http://www.gnu.org/licenses/>.
25 %
26
27 names_fields = fieldnames(uniform_ps);
28 nfields = length(names_fields);
29 uniform_cell = struct2cell(uniform_ps);
30 nrows = size(uniform_cell{1},1);
31 ncols = size(uniform_cell{1},2);
32
33 uniform_matrix3D = zeros(nrows,ncols,nfields);
34 for (ni=1:nfields)
35 uniform_matrix3D(:,:,ni) = uniform_cell{ni};
36 end