how to compress a variable size matrix into a fixed size one?

i need a function to convert variable size matrices into a fixed size of 25*25.

Answers (2)

You want to truncate first 25 rows and columns?
[m,n]=size(VariableSizeMatrix)
if (m>=25 && n>=25)
FixedSizeMatrix=VariableSizeMatrix(1:25,1:25)
end
if the size of VariableSizeMatrix is less than (25, 25) pad zeros or process according to your needs.
It depends on what kind of compression you want. It could be cutting out a part on the top or bottom, right, left or from the center. You could mean a linear or cubic interpolation, or a Lanzcos resampling using imresize.

5 Comments

Thank u... i want to compress the matrix without truncating it. my project deals with converting a sentance into a matrix of fixed size. the size of sentance may vary and hence the matrix size also varies. but i want a fixed size matrix so as to give it as an input to a neural network.....is it possible to give a variable size matrix as an input to a neural network....
@Vidhya: The question is not clear yet. What kind of result do you expect for a scalar, a [1 x 2] vector, a [2 x 1] vector, a [2x2] matrix and a [1 x 700] vectors, whose elements will not fit into a 25*25 matrix?
We cannot guess these details based on the fact, that you want to feed a NN with it.
Thank u sir......this is what i wanted to know.... so what i can understand now is that it is not possible to fit a 1*700 into a 25*25......
You cannot fit all unique 1*700 vectors into 25*25 without data loss, but if there are at least 75 duplicates you could do it.
What you probably want is something like to extract "features" from the sentences, in such a way that the 700 different sentences reduced down to a 25*25 matrix, with the mapping being by some kind of "essential similarity", with the NN so produced able to classify other sentences according to their essential similarities.
For example, if you were to classify each word independently by the possible parts of speech the word could be, then instead of the actual words, you could record the allowed parts of speech in sequence, and train the NN on those sequences. The resulting training should be able to predict what the actual parts of speech were for each word, because the same patterns occur repeatedly. You might find, for example, that ADJECTIVE-NOUN-NOUN seldom occurs, and so could deduce that the ADJECTIVE-(NOUN or ADJECTIVE)-NOUN pattern "big red box" is likely the ADJECTIVE-ADJECTIVE-NOUN pattern that occurs more often. Such as in the pattern "big heavy box".
thank u sir......this is what i wanted....thank u so much....

Sign in to comment.

Asked:

on 26 Sep 2013

Commented:

on 27 Sep 2013

Community Treasure Hunt

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

Start Hunting!