drill : outputs an array of objects from an array of structures or cell array of structures of structures. For example for superSegger's cell files, if structure is CellA{:}.coord.A calling A = drill ( CellA{:}, '.coord.A'), outputs A. (note : don't forget the dot at the beginning of str!) INPUT : dataA: array of structures str : string for name of field to be extracted OUTPUT : out : extracted array Copyright (C) 2016 Wiggins Lab Written by Paul Wiggins. University of Washington, 2016 This file is part of SuperSegger. SuperSegger is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SuperSegger is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SuperSegger. If not, see <http://www.gnu.org/licenses/>.
0001 function out = drill( dataA, str ) 0002 % drill : outputs an array of objects from an array of 0003 % structures or cell array of structures of structures. 0004 % 0005 % For example for superSegger's cell files, if structure is CellA{:}.coord.A 0006 % calling A = drill ( CellA{:}, '.coord.A'), outputs A. 0007 % (note : don't forget the dot at the beginning of str!) 0008 % 0009 % INPUT : 0010 % dataA: array of structures 0011 % str : string for name of field to be extracted 0012 % OUTPUT : 0013 % out : extracted array 0014 % 0015 % 0016 % Copyright (C) 2016 Wiggins Lab 0017 % Written by Paul Wiggins. 0018 % University of Washington, 2016 0019 % This file is part of SuperSegger. 0020 % 0021 % SuperSegger is free software: you can redistribute it and/or modify 0022 % it under the terms of the GNU General Public License as published by 0023 % the Free Software Foundation, either version 3 of the License, or 0024 % (at your option) any later version. 0025 % 0026 % SuperSegger is distributed in the hope that it will be useful, 0027 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0028 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0029 % GNU General Public License for more details. 0030 % 0031 % You should have received a copy of the GNU General Public License 0032 % along with SuperSegger. If not, see <http://www.gnu.org/licenses/>. 0033 0034 num = numel(dataA); 0035 cell_flag = iscell(dataA); 0036 tmp_array = cell(1,num); 0037 0038 for ii = 1:num 0039 if cell_flag 0040 try 0041 eval(['tmp_array{ii} = double(dataA{ii}', str,');']); 0042 catch 0043 tmp_array{ii} = NaN; 0044 end 0045 else 0046 try 0047 eval(['tmp_array{ii} = dataA(ii)', str,';']); 0048 catch 0049 tmp_array(ii) = {NaN}; 0050 end 0051 end 0052 if isempty(tmp_array{ii}) 0053 tmp_array(ii) = {NaN}; 0054 end 0055 end 0056 0057 try 0058 out = cell2mat(tmp_array); 0059 ss = size(dataA); 0060 out = reshape(out, ss); 0061 catch 0062 out=tmp_array; 0063 end 0064 0065 end