Equivalent of MATLAB’s colon operator in C/C++ with fftw
I am trying to rewrite some of my MATLAB functions in C/C++ and wanted to know if there’s an equivalent C/C++ operator to MATLAB’s colon operator :
For example I have a MATLAB code as the following:
N = [Nx Ny];
M = 3 * N / 2;
% Make a new set of 2D matrices of only zeros.
fk_pad = zeros(M(1), M(2));
% Get indices of the parts of the matrix we want to populate (zero padding)
for i = 1:2
ind_pad{i} = [1:N(i)/2 M(i)-N(i)/2+1:M(i)];
end
% Populate zero matrices with our input of fk
fk_pad(ind_pad{1},ind_pad{2}) = fk;
My code in C/C++ looks like:
static const int nx = 8, ny = 8;
static const int Mx = 3*nx/2, My= 3*ny/2;
double N[2] = {nx,ny};
// Make a new set of matrices of only zeros.
fftw_complex *fk_pad;
fk_pad = (fftw_complex*) fftw_malloc((Mx*My)* sizeof(fftw_complex));
memset(fk_pad, 42, (Mx*My) * sizeof(double)); //memset 42 initializes array to 1.42603e-105
But I am not sure how to implement the colon operator from the line: ind_pad{i} = [1:N(i)/2 M(i)-N(i)/2+1:M(i)];
in my above code, especially with fftw_malloc
which I am using in particular for FFTW3 library.
Thanks!
Read more here: Source link