Uploaded image for project: 'GMAT'
  1. GMAT
  2. GMT-2921

Arrays are corrupted when passed to MATLAB function

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: P1
    • Resolution: Fixed
    • Affects Version/s: R2012a
    • Fix Version/s: R2013a
    • Component/s: MATLAB Interface
    • Labels:
      None
    • Environment:

      Windows 7 Enterprise 64-bit
      2012-07-10 build

      Description

      The attached script calls passthrough.m and tries to pass an array to MATLAB and back.

      While passing from GMAT to MATLAB, the array is corrupted. For example, this array (in GMAT):

      11 12                  
      21 22                  
      31 32
      

      becomes this array (in MATLAB):

      11 22                  
      12 31                  
      21 32
      

      Passing from MATLAB back to GMAT seems to retain the structure of the array as it was on the MATLAB side.

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            marchand Belinda Marchand added a comment -

            The temporary workaround to this is to reshape your matrix into an array:

            Create Array patchSTMs[7,36] out[56];
            Create Variable I J Index;
            Create MatlabFunction yourMatlabFunction;
            Create String newRow;
            
            GMAT yourMatlabFunction.FunctionPath='the path to your m_file'; 
            
            BeginMissionSequence
            
            %
            % fill in the contents of patchState array here
            %    .
            %    .
            %    .
            
            newRow=' ';
            
            For I=1:1:8;
               For J = 1:1:7;
                  Index = (I-1)*7 + J;
                  out(Index) = patchStates(I,J);
               EndFor
            EndFor
            
            GMAT [outMatlab] = yourMatlabFunction(out);
            
            Report r out;
            Report r newRow;
            Report r outMatlab;
            
            
            

            then reshape back into a Matrix from your matlab script.

            Show
            marchand Belinda Marchand added a comment - The temporary workaround to this is to reshape your matrix into an array: Create Array patchSTMs[7,36] out[56]; Create Variable I J Index; Create MatlabFunction yourMatlabFunction; Create String newRow; GMAT yourMatlabFunction.FunctionPath='the path to your m_file'; BeginMissionSequence % % fill in the contents of patchState array here % . % . % . newRow=' '; For I=1:1:8; For J = 1:1:7; Index = (I-1)*7 + J; out(Index) = patchStates(I,J); EndFor EndFor GMAT [outMatlab] = yourMatlabFunction(out); Report r out; Report r newRow; Report r outMatlab; then reshape back into a Matrix from your matlab script.
            Hide
            jjkparker Joel Parker added a comment - - edited

            Attaching a spreadsheet (from Belinda) showing how matrices are being permuted in the GMAT->MATLAB interface.

            Show
            jjkparker Joel Parker added a comment - - edited Attaching a spreadsheet (from Belinda) showing how matrices are being permuted in the GMAT->MATLAB interface.
            Hide
            shughes Steven Hughes added a comment -

            CCB P1 2013a

            Show
            shughes Steven Hughes added a comment - CCB P1 2013a
            Hide
            jjkparker Joel Parker added a comment -

            We're getting some forum traffic asking about this bug. Can we bump it up a bit?

            Show
            jjkparker Joel Parker added a comment - We're getting some forum traffic asking about this bug. Can we bump it up a bit?
            Hide
            gmatloj Linda Jun added a comment -

            Updated MatlabInterface and CallMatlabFunction to handle matrix of row-major order (C++) and column-major order (MATLAB) when putting/getting one-dimensional array to/from MATLAB.
            Fix should be in 2012-10-16 build.

            Show
            gmatloj Linda Jun added a comment - Updated MatlabInterface and CallMatlabFunction to handle matrix of row-major order (C++) and column-major order (MATLAB) when putting/getting one-dimensional array to/from MATLAB. Fix should be in 2012-10-16 build.
            Hide
            jjkparker Joel Parker added a comment -

            Verified as fixed using 2012-12-20 build.

            Show
            jjkparker Joel Parker added a comment - Verified as fixed using 2012-12-20 build.
            Hide
            jjkparker Joel Parker added a comment -

            Tested in Matlab_IO_Array test case.

            Show
            jjkparker Joel Parker added a comment - Tested in Matlab_IO_Array test case.

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 2 hours, 5 minutes
                  2h 5m