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

            jjkparker Joel Parker created issue -
            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.
            jjkparker Joel Parker made changes -
            Field Original Value New Value
            Attachment GMAT-to-MATLAB-Array-Mapping.xlsx [ 12608 ]
            Hide
            shughes Steven Hughes added a comment -

            CCB P1 2013a

            Show
            shughes Steven Hughes added a comment - CCB P1 2013a
            shughes Steven Hughes made changes -
            Fix Version/s R2013a [ 10201 ]
            Assignee Joel Parker [ jjkparker ] Linda Jun [ gmatloj ]
            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?
            jjkparker Joel Parker made changes -
            Affects Version/s R2012a [ 10000 ]
            gmatloj Linda Jun made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            gmatloj Linda Jun logged work - 12/Oct/12 10:48 PM
            • Time Spent:
              2 hours
               
              <No comment>
            gmatloj Linda Jun made changes -
            Worklog Id 12019 [ 12019 ]
            Time Spent 2 hours [ 7200 ]
            Remaining Estimate 0 minutes [ 0 ]
            gmatloj Linda Jun logged work - 15/Oct/12 9:29 PM
            • Time Spent:
              5 minutes
               

              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
            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.
            gmatloj Linda Jun made changes -
            Worklog Id 12020 [ 12020 ]
            Time Spent 2 hours [ 7200 ] 2 hours, 5 minutes [ 7530 ]
            gmatloj Linda Jun made changes -
            Resolution Fixed [ 1 ]
            Assignee Linda Jun [ gmatloj ] Joel Parker [ jjkparker ]
            Status In Progress [ 3 ] Resolved [ 5 ]
            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.
            jjkparker Joel Parker made changes -
            Status Resolved [ 5 ] Verified [ 10002 ]
            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.
            jjkparker Joel Parker made changes -
            Status Verified [ 10002 ] Closed [ 6 ]

            Error rendering 'com.atlassian.jira.plugin.ext.subversion:subversion-commits-tabpanel'. Please contact your JIRA administrators.

              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