Ask Your Question

From Matlab to C

asked 2013-06-04 09:37:02 -0600

residentelvio gravatar image

i have to translate this line from Matlab to C

for i_orient=1:chrOrient

       stack = cat(3,resp{i_orient,:});

what I did is this, but I have to translate the cat function and I don t know why. resp is a MAt object in C

  for(int i_orient=1;i_orient<=achrOrient;i_orient++){
      //stack = cat(3,rpad{i_orient,:});
      inCompImg = stack.reshape(numColComp,rows*cols*achrScales);
      conspic = Tsquared.reshape(numColComp,rows*cols);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-06-04 09:54:40 -0600

cat isn't a standard function in C or C++ like it is in Matlab, you will have to implement the functionality yourself to match your needs. However, it is already weird that you only have two arguments for your matlab function, since documentation clearly states that min 3 arguments are needed.

I will explain the basics.


Cat function takes in account the number of dimensions and the matrices that need to be concatenated. 3 means you will use several 2D matrices into a 3D matrix structure.

C/C++ - OpenCV

Easiest way to do this is to create a 3D Mat structure, which can be done by using vectors. You can then copy each Mat that needs to be concatenated into the specified vector.

Example code:

Mat matrix_1;
Mat matrix_2;
vector<Mat> result;

If you want it for an arbitrary number of matrices, create a for loop structure.

edit flag offensive delete link more


Thanks to explain. Maybe as I don t know a lot about Matlab I didn t explain that resp become from this line


Maybe is important to explain the line of before. I searched something about {} and I did not understand what it do well

residentelvio gravatar imageresidentelvio ( 2013-06-04 10:28:26 -0600 )edit

My advice, before translating matlab code to C/C++ using OpenCV, is to understand the actual matlab algorithm. Else there is litteraly no beginning. Also, problems about Matlab code shouldn't be adressed at this forum... read the FAQ to know why.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-06-05 01:56:30 -0600 )edit

Ok I understand what is a Cell. In my case I think I can use the vector Mat in a loop to obtain what I need

residentelvio gravatar imageresidentelvio ( 2013-06-05 15:13:02 -0600 )edit

Question Tools


Asked: 2013-06-04 09:37:02 -0600

Seen: 407 times

Last updated: Jun 04 '13