I have two arrays of different size that I am trying to compare. I am therefore trying to extend the smaller array to the bigger one. I have been using the padarray function to add 0 values around the extent of the smaller array. The problem I am encountering is when one matrix has an even number of rows/columns and the other a odd number of rows/columns. For example;
A is a 302x206 logical array
B is a 335x230 logical array
If I use
B = paddarray(B,[16,12])
I am left with a 334x230 logical array. Whilst if I use
B = padarray(B,[17,12])
I am left with a 336x230 logical array.
How can I overcome this problem as the function does not allow decimals to be place in the cell array.
>> help padarray padarray not found. >>
So, don't know what it is; apparently after R2012b.
C=logical(zeros(size(B)); % allocate size of larger C(1:size(A,1),1:size(A,2))=A; % place smaller inside
Alternatively, to pad the smaller,
A=[A repmat(zeros(size(A,1),size(B,2)-size(A,2)),1,1)]; % add columns A=[A;repmat(zeros(size(B,1)-size(A,1),size(A,2)),1,1)]; % add rows
NB: the number of rows while adding columns has to be same as shorter and order is significant. If add rows first then have to only have shorter number of columns to maintain consistent sizes in the concatenation.
Use padarray twice. The first time with the default 'both' direction the second time with just 'pre' or 'post' to add the extra row/col before or after.
Have to have the subset area the same size as the insert--means have to compensate for the start location (and not forget to subtract one for the endpoint location from the number of elements returned by size())
The first solution used (1,1) as origin so 1:size() worked there as (1:1+size()-1) = 1:size()