0

I am trying to convert my Matlab code to C++ using Eigen library and I am stuck at the part where I have to initialise a 3 dimensional variable SMat (order of 26x10x181) with data type double from a 2 dimensional variable S (order of 10x181).Also I seem to get error where I need to perform scalar with vector multiplication of Freq(order 26x1) and delay(181x10). I am confused on how to represent delay(angle,:) ,S(:,angle) and StMat(iFreq,:,angle) as given in the matlab code below, using Eigen library inside for loops.

for freqBin=1:26
    for angle=1:181
        S(:,angle)=exp(-1i*(Freq(freqBin).*delay(angle,:)')); %1st command 
    end 
    SMat(freqBin,:,:)=S;%2nd command
end
%%
 for freqBin=1:26
        for angle=1:181
 StM(:,1) = StMat(iFreq,:,angle);%3rd command---- order of StM 10x1

In my C++ code , Freq is of data type VectorXd (since I used setLinspaced() for its definition) and delay is of data type MatrixXd. I tried to use .cwiseProduct() but it resulted in error.I referrred to this site, but the output of the example mentioned gave me a 5x5 matrix full of 47. The effect of 10 is not visible. Can anyone suggest me a command for element by element multiplication and initialisation of 3D matrix?Please help.

Ema
  • 79
  • 1
  • 6
  • Have a look at the Tensor module, especially the `chip` function: https://bitbucket.org/eigen/eigen/src/306356e228ecbc70ddc0bcd5880bfa9acb9a16e7/unsupported/Eigen/CXX11/src/Tensor/README.md?at=default&fileviewer=file-view-default#markdown-header-operation-chipconst-index-offset-const-index-dim – chtz Mar 10 '18 at 16:24
  • I tried to do a simple initialization according to the link by manually putting arguments, for example Eigen::Tensor a(3,3,3);a.setZero();a(0,1,2)=1; But how do I bring the effect of : operator in my matlab command SMat(freqBin,:,:)=S;//2nd command?@chtz – Ema Mar 11 '18 at 03:30
  • Is there a simpler way other than taking `for loops` to do this? – Ema Mar 11 '18 at 03:40
  • Also if I declare SMat as Tensor, I am not able to assign it with a MatrixXd data type variable S. – Ema Mar 11 '18 at 04:04

0 Answers0