Building Multidimensional Arrays from simple arrays Hi I am trying to write a functiont that will build a 2x4 array based on 2 1x4 arrays.

the two relevant functions are below. The first function gets information from some sensors and outputs it (I think) as a 1x4 array.

The second function is the problem and I have attached the error messages.

{
double quatCalib_mat[2][4];
double quatCalib_ABC[4];
double quatCalib_GHI[4];   

 double  get_quat(Adafruit_BNO055 ref, double quatArray[])
{
  imu::Quaternion quat2 = ref.getQuat();

  quatArray[0]= quat2.w();
  quatArray[1]= quat2.x();
  quatArray[2]= quat2.y();
  quatArray[3] =quat2.z();

}

void Calibrate()
{
quatCalib_ABC=get_quat(bnoABC, quatCalib_ABC);

quatCalib_GHI=get_quat(bnoGHI, quatCalib_GHI);

quatCalib_mat= {
  {quatCalib_ABC},
  {quatCalib_GHI}
  };
}


the error messages

Arduino: 1.6.9 (Windows 7), Board: "Arduino/Genuino Uno"

E:\UNI2016\thesis\gizmo programming\Thesis_V3_M\Thesis_V3_M.ino: In function 'void Calibrate()':

Thesis_V3_M:101: error: incompatible types in assignment of 'double' to 'double [4]'

 quatCalib_ABC=get_quat(bnoABC, quatCalib_ABC);

              ^

Thesis_V3_M:103: error: incompatible types in assignment of 'double' to 'double [4]'

 quatCalib_GHI=get_quat(bnoGHI, quatCalib_GHI);

              ^

Thesis_V3_M:105: error: assigning to an array from an initializer list

 quatCalib_mat= {

              ^

exit status 1
incompatible types in assignment of 'double' to 'double [4]'


Cheers

Alex
As Mikael Patel said, the compiler is already hinting you about what is
wrong. But there are other issues.


In get_quat(), there is no point in returning anything, as the
function is already putting the relevant info in the quatArray
parameter.
Then, when calling get_quat(), you don't want to assign the return
value to anything.
You cannot assign an array like you did, unless it's an
initialization. I would explicitly copy the sub-arrays with
memcpy():




void get_quat(Adafruit_BNO055 ref, double quatArray[])
{
    imu::Quaternion quat2 = ref.getQuat();
    quatArray[0] = quat2.w();
    quatArray[1] = quat2.x();
    quatArray[2] = quat2.y();
    quatArray[3] = quat2.z();
}

void Calibrate()
{
    get_quat(bnoABC, quatCalib_ABC);
    get_quat(bnoGHI, quatCalib_GHI);
    memcpy(quatCalib_mat[0], quatCalib_ABC, sizeof quatCalib_ABC);
    memcpy(quatCalib_mat[1], quatCalib_GHI, sizeof quatCalib_GHI);
}


It could be noted that storing the calibration array twice (as both one
2D array and two 1D arrays) is a waste of RAM. You could get rid of the
1D arrays and have instead get_quat() fill the lines of the 2D array
directly:

void Calibrate()
{
    get_quat(bnoABC, quatCalib_mat[0]);
    get_quat(bnoGHI, quatCalib_mat[1]);
}