Error when filling a matrix using Eigen

I have the MATLAB code:

1
2
3
4
5
6
7
8
9
Nx = 10;
Ny = 10; 
%X,Y defined
u = (Y-0.5).^2 .* sin( (2*pi / Lx) * X); %Y.^2 .* sin( (2*pi / Lx) * X);
uh = fft(u,[],2);
%use discrete transform with m rather than n points, where m >= 3N/2
[Ny Nx]=size(uh);
m=Nx*3/2;
uhp=[uh(:,1:Nx/2) zeros(Ny,(m-Nx)) uh(:,Nx/2+1:Nx)];% pad uhat with zeros

so the MATLAB code, is building the matrix uhp by filling it from matrix uh.
In the C++ code I did the following which I thought was correct:
1
2
3
4
5
6
7
8
9
static const int nx = 10;
static const int ny = 10; 
static const int mm = nx* 3/2;

Eigen::Matrix<std::complex<double>, (ny+1), mm> uhp;
uhp.setZero();
uhp(all,seqN(0,nx/2)) = uh(all,seqN(nx/2+1,nx));
uhp(all,seqN(nx/2+1,nx)).setZero(); //ERROR
uhp(all,seqN(nx,mm))= uh(all,seqN(nx/2+1,nx)); //ERROR 

but this returns the error:

 Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>::Block(XprType&, Eigen::Index, Eigen::Index, Eigen::Index, Eigen::Index) [with XprType = Eigen::Map<Eigen::Matrix<std::complex<double>, -1, -1>, 0>; int BlockRows = -1; int BlockCols = -1; bool InnerPanel = true; Eigen::Index = long int]: Assertion `startRow >= 0 && blockRows >= 0 && startRow <= xpr.rows() - blockRows && startCol >= 0 && blockCols >= 0 && startCol <= xpr.cols() - blockCols' failed.
Aborted

I am aware that uh and uhp are not the same size but not sure how to fix it, or set it up similarly to MATLAB
Last edited on
Consider using MATLAB to convert MATLAB code to C/C++:

https://www.mathworks.com/matlabcentral/answers/396271-how-to-convert-matlab-code-to-c-code

https://www.mathworks.com/products/matlab-coder.html

FYI, I can't say how useful this would be since I don't use MATLAB.
@George P
Thanks, but unfortunately I was never able to get this "MATLAB coder" to work really.
Really, I am trying to say something like return all rows and the last 5 columns of uhp here : uhp(all,seqN(nx+1,mm)) but this is wrong.
Maybe, just maybe, you should ask in a MATLAB support forum (if there is one) how to get the coder to work.

The company created and sells it, they should help getting it to work.

Converting MATLAB code to C++ is a very specialized task.

I'm outta here.

Pax!
I did find the issue and to fix it I used seq() instead of seqN()
Topic archived. No new replies allowed.