I'm having a rough time with pointers, can someone help me a little bit?

I'm trying to initialize a double (double) pointer inside a struct array, but I'm somehow doing it wrong.. Example:

```
struct MyStruct
{
    double **matrix;
};

double **CalculateMatrix(...)
{
    double **matrix = (double**)malloc(ROWS * sizeof(double*));
    for (int i = 0; i < ROWS; i++)
        matrix[i] = (double*)malloc(COLS * sizeof(double));
    // + assign some values
    return matrix;
}

void Initialize(struct MyStruct *structs, int size)
{
    for (int i = 0; i < size; i++)
        // Here structs[i].matrix holds the correct matrix values
        structs[i].matrix = CalculateMatrix(...);
}

int main()
{
    struct MyStruct *structs = (struct MyStruct*)malloc(SIZE * sizeof(struct MyStruct));
    Initialize(structs, SIZE);
    // but once the function returns, matrix values are completely different
}

```

Sorry if it's duplicated, I couldn't find anything