Jul 9, 2022 at 5:43pm UTC
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 Jul 9, 2022 at 6:12pm UTC
Jul 9, 2022 at 6:11pm UTC
@George P
Thanks, but unfortunately I was never able to get this "MATLAB coder" to work really.
Jul 9, 2022 at 6:20pm UTC
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.
Jul 9, 2022 at 6:26pm UTC
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!
Jul 10, 2022 at 3:49am UTC
I did find the issue and to fix it I used seq()
instead of seqN()