time | Calls | line |
---|
| | 218 | function [template, template_is0x0, updateIdx] = getTemplate(template, b, template_is0x0)
|
| | 219 | % Helper function to identify the correct output template for horzcat.
|
| | 220 | %
|
| | 221 | % We start with an uninitialized template which will be initialized by the first
|
| | 222 | % tabular value that we encounter. If the template was initialized from a 0x0
|
| | 223 | % table/timetable then we would update it if we encounter a non-0x0
|
| | 224 | % table/timetable. If all inputs are 0x0, we would keep the template obtained
|
| | 225 | % from the first input.
|
| | 226 | %
|
| | 227 | % For templates initialized to a table if later on we come across a timetable,
|
| | 228 | % then we would update the template with the timetable, otherwise the template
|
| | 229 | % would remain unchanged. For templates initialized to a timetable, we would
|
| | 230 | % skip any tables or timetables that follow it (we would still do some error
|
| | 231 | % checks).
|
| | 232 | %
|
| | 233 | % The template would be a tabular of the correct type and correct number of
|
| | 234 | % rows. updateIdx informs the caller if the template is updated, so that it can
|
| | 235 | % update the template index
|
| | 236 |
|
< 0.001 | 4 | 237 | updateIdx = false;
|
< 0.001 | 4 | 238 | if isa(b,'tabular')
|
0.001 | 4 | 239 | b_is0x0 = sum(size(b)) == 0;
|
< 0.001 | 4 | 240 | if isa(template,'table')
|
< 0.001 | 2 | 241 | if isa(b,'table')
|
< 0.001 | 2 | 242 | if template_is0x0 && ~b_is0x0
|
| | 243 | % Reinitialize the template as it was previously initialized
|
| | 244 | % from a 0x0 table.
|
| | 245 | template = b;
|
| | 246 | template_is0x0 = false;
|
| | 247 | updateIdx = true;
|
< 0.001 | 2 | 248 | end
|
| | 249 | % If the template was initialized from non-0x0 table, then we skip
|
| | 250 | % any tables we see later on.
|
| | 251 | else % b is a timetable
|
| | 252 | % Reinitialize the template to be a timetable. Since we saw a table
|
| | 253 | % before a timetable, this would be an error and the caller function
|
| | 254 | % would throw the appropriate error message.
|
| | 255 | template = b;
|
| | 256 | template_is0x0 = b_is0x0;
|
| | 257 | updateIdx = true;
|
| 2 | 258 | end
|
< 0.001 | 2 | 259 | elseif isa(template,'timetable')
|
| | 260 | if isa(b,'timetable')
|
| | 261 | if template_is0x0
|
| | 262 | if ~b_is0x0
|
| | 263 | % Reinitialize the template as it was previously initialized
|
| | 264 | % from a 0x0 timetable.
|
| | 265 | template = b;
|
| | 266 | template_is0x0 = false;
|
| | 267 | updateIdx = true;
|
| | 268 | end
|
| | 269 | % Otherwise b is also a 0x0 timetable, so we do not update the
|
| | 270 | % template.
|
| | 271 | % If the template was initialized from a non-0x0 timetable, we skip
|
| | 272 | % any timetables that follow.
|
| | 273 | end
|
| | 274 | else % t is a table
|
| | 275 | % We have already initialized the template with a timetable, so for
|
| | 276 | % tables following that, just check for some error cases and move
|
| | 277 | % on without updating the template.
|
| | 278 | if template_is0x0 && b.rowDim.length ~= 0
|
| | 279 | % horzcating 0x0 timetable with Mx0 tables is not allowed
|
| | 280 | error(message(strcat('MATLAB:table:horzcat:Timetable0x0AndTable')));
|
| | 281 | end
|
| | 282 | end
|
< 0.001 | 2 | 283 | else % uninitialized
|
| | 284 | % Initialize the template with the first tabular input that we see
|
< 0.001 | 2 | 285 | template = b;
|
< 0.001 | 2 | 286 | template_is0x0 = b_is0x0;
|
< 0.001 | 2 | 287 | updateIdx = true;
|
< 0.001 | 4 | 288 | end
|
| | 289 | elseif iscell(b)
|
| | 290 | % Reinitialize the template with the current size, if the template was
|
| | 291 | % initialized from a 0x0 table or was uninitialized.
|
| | 292 | b_is0x0 = sum(size(b)) == 0;
|
| | 293 | if ~b_is0x0 && (~isa(template,'tabular') || (isa(template,'table') && template_is0x0))
|
| | 294 | b = cell2table(b);
|
| | 295 | template = b;
|
| | 296 | template_is0x0 = true;
|
| | 297 | updateIdx = true;
|
| | 298 | end
|
| | 299 | elseif isnumeric(b) && isequal(b,[])
|
| | 300 | % Skip [] inputs
|
| | 301 | else
|
| | 302 | error(message(strcat('MATLAB:table:horzcat:InvalidInput')));
|
< 0.001 | 4 | 303 | end
|