Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to enlarge matrices in Matlab?

Status
Not open for further replies.

pyrite

Member level 2
Joined
Aug 9, 2004
Messages
44
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
0
Hi,
I have a matrix (size n x m) in matlab. And I want to enlarge the matrix size to n+2x, m+2y) by adding zeros around the original n x m matrix.

Example:
original 2x2 matrix
1 2
3 4

New 4x4 matrix [0 0 0 0; 0 1 2 0; 0 3 4 0; 0 0 0 0]
0 0 0 0
0 1 2 0
0 3 4 0
0 0 0 0

How can I do it in matlab?

Thanks in advance!
 

matlab enlarge matrix

hi,
if i understand you rigth, you want to zero pad a matrix, rigth.
well usaly you do it in order to do soom calc on it, and most of the matlab function do contain another argomant that tells them to zeropad it's inputs before using it.
so you should chack with the help XX about whtere your function has this,
and any way here's a code that does conv on a pic with a mask. and then in order to do mac on the frq plane we had to do fft and zeropading before it and it was done like this:
I=imread('cameraman.tif'); %Read Image
subplot(2,1,1);imshow(I)

h=ones(9);
% h=[0 -1 0; -1 4 -1; 0 -1 0];

J=conv2(I,h,'full');
subplot(2,1,2);imshow(J,[])

[m,n]=size(J);
FI=fft2(I,m,n);
figure
subplot(2,2,1);imshow(log(abs(fftshift(FI))+1),[])
% [m,n]=size(I);
% h(m,n)=0; %Zero padding
Fh=fft2(h,m,n);
subplot(2,2,2);imshow(log(abs(fftshift(Fh))+1),[])
FJ=FI.*Fh;
Jfreq=ifft2(FJ);
subplot(2,2,3);imshow(log(abs(fftshift(FJ))+1),[])
subplot(2,2,4);imshow(real(Jfreq),[])

that's for doing an fft with zeropading.
hope that's help,
iftah.
 

Re: matlab matrix help!

New_Matrix = zeros(n+2,m+2) ;
New_Matrix(2:n+1,2:m+1) = Old_Matrix


Hope it help

mayyan
 

    pyrite

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top