-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtruncateCellArray.m
47 lines (42 loc) · 1.23 KB
/
truncateCellArray.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
% FILE: truncateCellArray.m
%
% FUNCTION: truncateCellArray
%
% CALL: truncatedCellArray = truncateCellArray(cellArray, new_size)
%
% The functions truncate the input cell array to the new_size, if no new
% size is given the output cell array has the same length as the input
%
% INPUTS:
% cellArray - cell array to truncate
% new_size - the new size of the cell array
%
% OUTPUTS:
% truncatedCellArray - the truncated cell array
%
%
% Author: Leonard-Gabriel Necula
% Created: December 24 2020
% Updated: January 18 2021
function truncatedCellArray = truncateCellArray(cellArray, new_size)
if nargin < 1
disp('Inputs: cell array and new size');
return;
elseif isempty(cellArray)
disp('Empty input. Nothing to truncate');
return;
end
if nargin < 2
disp('Size was not specified.');
truncatedCellArray = cellArray;
return;
elseif isempty(new_size)
disp('Empty new size');
truncatedCellArray = cellArray;
return;
end
truncatedCellArray = cell(new_size, 1);
for i = 1 : new_size
truncatedCellArray{i} = cellArray{i};
end
end