Is it possible to assign a bidimensional array to a vector? I need to meshgrid 2 unidimensional array to obtain 2 bidimensional array. I can work just with vector. but when I have to meshgrid I don t know how it works.
Example:

Code:
```vector<double>x(cols);
vector<double>y(rows);
vector<double>X(rows*cols);
vector<double>Y(rows*cols);

for(int i=0;i<cols;i++){
for(int z=0;z<rows;z++){
X[i][z]=x[i];  //error
Y[i][z]=y[z];  //error
}
}```
Using arrays I can do it, but I need to do with vectors. Thanks to help evenctually

2. Yes, vectors can be nested inside vectors.
Code:
```#include <vector>
#include <iostream>
#include <iomanip>
using namespace std;
int main ( ) {
const int rows = 10;
const int cols = 20;
vector< vector<double> > matrix( rows, vector<double>(cols,42) );
for ( int r = 0 ; r < rows; r++ ) {
for ( int c = 0 ; c < cols ; c++ ) {
cout << matrix[r][c] << " ";
}
cout << endl;
}
}```
The only real catch is that > > needs a space, to prevent it being confused with >> (which has other connotations).

3. So if I understood well in my case:

Code:
```vector<double>x(cols);
vector<double>y(rows);
vector< vector><double> > X(rows,cols);
vector< vector><double> > Y(rows,cols);

for(inti=0;i<cols;i++){  for(int z=0;z<rows;z++){
X[i][z]=x[i];
Y[i][z]=y[z];
}
}
```
Is it true? thanks

4. Code:
```vector< vector<double> > X(rows, vector<double>(cols) );
vector< vector<double> > Y(rows, vector<double>(cols) );```
Kurt

5. Originally Posted by Salem
The only real catch is that > > needs a space, to prevent it being confused with >> (which has other connotations).
Correction: It needs a space if you are using C++98/03. With C++11 and forward, it's optional.

Also, you should iterate over rows first, then columns. It can make a lot of difference for tight loops, and it's such an easy optimization that it's really viable to do all the time.

6. Is it possible to pass a vector of vector to a function?
Code:
```void pre_filter_Computations(vector< vector<double> > radius(rows,  vector<double>(cols) ),vector< vector<double> > theta(rows, vector<double>(cols) ),int cols,int rows);

Mat logGabor(vector< vector<double> >  filter(rows, vector<double>(cols) ),Mat imfft,double r_o, double theta_o,double sigma_theta,vector< vector<double> >radius(rows, vector<double>(cols) ),vector < vector<double> >theta(rows,vector<double>(cols) ),int cols,int rows,double sigma_r,int *padSize);
```

I have some errors:

Multiple markers at this line :
-declared here
-expected ',' or '...' before '(' token

7. Yes, it is. But you will have to learn how to declare function prototypes and how to pass arguments correctly first. And read about references while you're at it. Copying vectors can be expensive.

8. The problem is in my University we just studied C language. I m working to a thesis ' project and I work with image-processing and OpenCV so i have to use C++ in some parts of the works. I understood how to pass it to a function , but now i have en error invoking the function. If r is the vector of vectors:

funtion(r,cols,rows);

I have error. I just put the name of the variable.

9. I'm going to guess that the code you posted an hour ago is the source of the problem:

Code:
```void pre_filter_Computations(vector< vector<double> > radius(rows,  vector<double>(cols) ),vector< vector<double> > theta(rows, vector<double>(cols) ),int cols,int rows);

Mat logGabor(vector< vector<double> >  filter(rows, vector<double>(cols) ),Mat imfft,double r_o, double theta_o,double sigma_theta,vector< vector<double> >radius(rows, vector<double>(cols) ),vector < vector<double> >theta(rows,vector<double>(cols) ),int cols,int rows,double sigma_r,int *padSize);```
These are not not well written prototypes because there are too many details. Let's forget about vector for a moment:
Code:
``` void pre_filter_Computations(array radius, array theta, int cols, int rows);

Mat logGabor (array filter, Mat imfft, double r_o, double theta_o, double sigma_theta, int cols, int rows, double sigma_r, int *padSize);```
I took special care to emphasize the types of your parameters. When you write a parameter list, there only has to be enough information to identify the type. That means that you want to include the class name and the template instantiation, like this: "vector<vector<double> > paramName". If the type is constant, volatile, mutable, or whatever, you will modify the type accordingly. The rest of it is too much detail.

When you call your function, you will want to set up objects to act as arguments. Then you include their names, in order according to the parameter list, where you call.

I would also like to emphasize:
• that vectors can give you column- and row-size information
• it might be best to stick to one matrix type
• if you have a matrix type, it is likely optimized for mathematical programming
• and that vector is not the best math matrix

10. Show relevant snippets of code and the complete error. Otherwise we can only guess.
But you really should spend some time learning C++.
Anyway, here is how you would pass a vector to a function:

auto foo(const std::vector<std::vector<T>>& myvector) -> void
// Or void foo(const std::vector<std::vector<T>>& myvector) if you are using an older compiler

std::vector<std::vector<T>> myvector;
// Put stuff in vector
foo(myvector);

Remove "const" if you are intending the function to modify it. T can be any type - int, double, your custom class, etc.

11. Originally Posted by Elysia
T can be any type - int, double, your custom class, etc.
T can be almost any type. Generally speaking, the type needs to support value semantics.

A custom class with a private copy constructor, for example, doesn't work too well within a vector.