How do I increase the columns of an NxM matrix to become NxN? (N>M) Not using reshape.
2 views (last 30 days)
Show older comments
Hi all,
I was hoping somebody could help me with this. Essentially, I have a 50x10 matrix and I want the matrix to be 50x50. I am trying to insert a couple of columns in between each column that I already have and then I want to make sure the values that are inserted have a linear trend between them. Here is an example of what I am trying to say:
A = [0 4 5;
0 5 1;
10 8 1;
2 4 6;
1 2 3] (5x3)
and I want the new matrix to be:
Anew = [0 2 4 4.5 5;
0 2.5 5 3 1;
10 9 8 4.5 1;
2 3 4 5 6;
1 1.5 2 2.5 3] (5x5)
Doing this by hand is easy for an example this small, but is there a way to do this via computations, or a function? I need to be able to do it for much larger matrices.
I hope my question is clear. Thanks in advance.
0 Comments
Accepted Answer
Star Strider
on 26 Jan 2015
This works:
vi = linspace(1, 3, 5); % Interpolation Vector
for k1 = 1:size(A,1)
Anew(k1,:) = interp1([1:3], A(k1,:), vi, 'linear');
end
2 Comments
Star Strider
on 26 Jan 2015
My pleasure!
(The most sincere expression of appreciation here on MATLAB Answers is to Accept the Answer that most closely solves your problem.)
More Answers (1)
Image Analyst
on 26 Jan 2015
If you have the Image Processing Toolbox, use imresize():
Anew = imresize(A, [5,5], 'bilinear')
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!