I used replicate.m to generate some padding on a string cell array.
AA = {'blank'};
myLabels = {'fish','beer'};
myLabels = [ myLabels (replicate (AA,1,3)) ]
myLabels =
'fish' 'beer' 'blank' 'blank' 'blank'
4
08 Dec 2008
REPLICATE
Create a larger array by expanding each element of an array into a subarray.
This is a more elegant and faster solution for the 2D case. The next version of the file will have this solution. Unfortunately, KRON gives 2D results when Y is 3D, so a different approach is needed in the 3D case.
A = reshape(1:6,[1 3 2]);
S = [2 2 2];
A(kron(reshape(1:numel(A),size(A)),ones(S)))
replicate(A,S)
Comment only
06 Dec 2008
REPLICATE
Create a larger array by expanding each element of an array into a subarray.
Indexing with KRON is equally flexible:
% data
A = {12 {'yy' 'xxx'} ; 'aaa' rand(2)}
nr = 3 ;
nc = 5 ;
% engine
B = A(kron(reshape(1:numel(A),size(A)),ones([nr nc])))
Comment only
05 Dec 2008
REPLICATE
Create a larger array by expanding each element of an array into a subarray.
KRON works for floats and doubles but not integral types, structs, or cell arrays. KRON relies on multiplication, while REPLICATE uses only indexing, thus making it more flexible.
Comment only