<div dir="ltr"><div><div><div>Hi Dear<br><br></div>I have a problem in using a variable for loop in using RcppArmadillo library.<br></div>I have pasting here my code. It is executing but not giving the same results as its R code version gives. The results produced by it are really weird. I have checked it step by step. It is because of the for (int q=0; q<i; q++). I request tp please help how to handle it in cpp.<br><br></div><div>The another question is I want to multiply the cube b(i, ,) by a scalar. How can we consider the entire columns and slices of a cube for each of the rows.  "b(span(i), span(), span())"  is not working for me. <br></div><div><br></div>Thank you<br><br>#include <RcppArmadillo.h><br>using namespace Rcpp;<br>using namespace RcppArmadillo;<br>//[[Rcpp::depends(RcppArmadillo)]]<br>//[[Rcpp::export]]<br>arma::cube up(arma::mat a){<br>  int m = a.n_cols;<br>  int n = a.n_rows;<br>  int p = a.n_rows;<br>  arma::cube b(n, m, p);<br>  for(int i=0; i<n; i++){<br>      for(int j=0; j<m; j++){<br>        for(int q=0; q<i; q++){<br>         if(q==0){<br>           b(i, j, q) = a(i, j);<br>         }<br>         else{<br>           b(i, j, q) = 0.0;<br>         }<br>      }<br>    }<br>  }<br>  return b;<br>}<br clear="all"><div><div><div><div><br>-- <br><div class="gmail_signature"><i><font face="comic sans ms,sans-serif">Amina Shahzadi</font></i></div>
</div></div></div></div></div>