Changing dimensions of matrix

Say that we have two matrices.One is a 32*15 matrix and the other is 66*31 matrix.It is required to determine where this(32,15) matrix is located on the (66,31) matrix. Then you get the 3rd matrix with of size (66,31) with values known at the (32,15) positions.Then how do I fill the matrix with interp2

Answers (2)

Image Analyst
Image Analyst on 24 Jun 2017
See attached demo for normxcorr2() where you can find a template matrix inside a larger matrix.
Here's one way using isequal().
% Create sample data
bigMatrix = randi(9, 66, 31)
% Get smaller 32*15 matrix from location 3,5, so we'll know it definitely exists in bigMatrix.
smallMatrix = bigMatrix(3:34, 5:19)
% Now find small amtrix in big matrix
for col = 1 : 17
for row = 1 : 35
subMatrix = bigMatrix(row:row+31, col:col+14);
if isequal(subMatrix, smallMatrix)
message = sprintf('Small matrix found in large matrix at location row=%d, col = %d', row, col);
uiwait(helpdlg(message));
end
end
end
If you know the match occurs only once, you can put a "break;" after the uiwait().

4 Comments

Hey i guess I could not clear this out.So basically what I wanted is that since I have (32,15) and (66,31) matrix,If I insert zeros after each elements of (32,15) it will become a (64,30).Then we add a 0 column(2) and row at the end to makie it (66,31).Then how do I fill in the zero values by interpolating.How could I use the interp2.m then
There is nothing to interpolate to. Do you mean "extrapolate" instead of interpolate? If so, I'd probably use polyfit() to fit a quadratic to the last few rows and columns, then use polyval() to get the extrapolated values.
I think that part then could be filled up will then be inward interpolation maybe regionfill
How? There is no surrounding region to fill it in if you just have zeros going out to the edge of the image. You'd at least need a line of valid image data going around the edge of the data to use regionfill(), though I've never tried it with a mask that touches the edge of the image. Maybe it won't throw an error (won't know until I try) but I think the results, if any, would be unpredictable and unreliable.

Sign in to comment.

Asked:

MSP
on 24 Jun 2017

Commented:

on 25 Jun 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!