Last active
August 29, 2015 14:21
-
-
Save jnkather/aa95e29d901cfd24f3dc to your computer and use it in GitHub Desktop.
Create a 1D or 2D stairstep array in Matlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% (c) Jakob Nikolas Kather 2015 | |
% contact: http://www.kather.me | |
% aim is to create a 1D-stairstep array, i.e. transform | |
% 1 2 3 4 to | |
% 1 1 1 2 2 2 3 3 3 4 4 4 | |
matrix = 1:4 | |
newSize = 3 | |
step_matrix = reshape(repmat(matrix,newSize,1),1,[]) | |
% aim is to create a 2D-stairstep array, i.e. transform | |
% 1 2 | |
% 3 4 | |
% to | |
% 1 1 2 2 | |
% 1 1 2 2 | |
% 3 3 4 4 | |
% 3 3 4 4 | |
matrix = reshape(1:4,[],2)' | |
oldSize = 2 | |
newSize = 4 | |
[xold yold] = meshgrid(linspace(0,1,oldSize),linspace(0,1,oldSize)); | |
[xnew ynew] = meshgrid(linspace(0,1,newSize),linspace(0,1,newSize)); | |
step_matrix = interp2(xold,yold,matrix,xnew,ynew,'nearest') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment