Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
boundmirrorexpand

Subject: boundmirrorexpand

From: saeede

Date: 30 Mar, 2013 16:46:06

Message: 1 of 2

Hi
i have a matrix,for example
A=[1 2 3 11;4 5 6 12;7 8 9 13]
i don't know how obtain B.
B = BoundMirrorExpand(A) will yield

        5 4 5 6 12 6
        2 1 2 3 11 3
        5 4 5 6 12 6
        8 7 8 9 13 9
        5 4 5 6 12 6

function B = BoundMirrorExpand(A)
% Expand the matrix using mirror boundary condition
%
% for example
%
% A = [
% 1 2 3 11
% 4 5 6 12
% 7 8 9 13
% ]
%
% B = BoundMirrorExpand(A) will yield
%
% 5 4 5 6 12 6
% 2 1 2 3 11 3
% 5 4 5 6 12 6
% 8 7 8 9 13 9
% 5 4 5 6 12 6
%

[m,n] = size(A);
yi = 2:m+1;
xi = 2:n+1;
B = zeros(m+2,n+2);
B(yi,xi) = A;
B([1 m+2],[1 n+2]) = B([3 m],[3 n]); % mirror corners
B([1 m+2],xi) = B([3 m],xi); % mirror left and right boundary
B(yi,[1 n+2]) = B(yi,[3 n]); % mirror top and bottom boundary
?
thanks

Subject: boundmirrorexpand

From: Bruno Luong

Date: 30 Mar, 2013 17:07:15

Message: 2 of 2

B = A(:,[2 1:end end-1]);
B = B([2 1:end end-1],:)

% Bruno

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us