I have problems for using NASA's General Mission Analysis tool (GMAT). I am trying to save a data in report file (SMA or Semi Major Axis) into a new array. This SMA has 25 lines. I have tried this code:

Create Array anArray[25,1];    
For a=1:25

This code produced an error, it said "matrix is mismatched".

So, I tried to change the dimension of array, this code is become:

Create Array anArray[1,1];    
For a=1:1

It works, but just read the latest data.

So I guess, the code just read the final data, I don't know how to fix it. Please help me.


1 Answer 1


Based on your example, it looks like an indexing problem.

You defined anArray to be two-dimensional, with 25 rows and 1 column. Then, in your For loop, you access the array with a one-dimensional index. When you do this, GMAT assumes that the first index, the row index, is always 1. To check this, look at the "Array" section of the reference guide.

So in the first iteration of your For loop, a=1, so your array assignment looks like this: anArray(1, 1) = DefaultSC.Earth.SMA;. This is fine because (1, 1) exists in the array. Then, on the second iteration, a=2, your array assignment will look like this: anArray(1, 2) = DefaultSC.Earth.SMA;. This breaks because there is only one column in anArray.

To fix your problem, do one of the following:

  • Change anArray to one-dimensional
  • Flip the dimensions of anArray in your definition (so that it has 25 columns and only 1 row)
  • Keep anArray two-dimensional and be more explicit when you are slicing it

Here is some example code:

Create Array arr_row[25,1] arr_col[1,25] arr_one[25];


For I = 1:1:10;
    arr_row(I) = I  % won't work
    arr_row(I, 1) = I  % will work and is better form
    arr_col(I) = I  % will work but is ambiguous
    arr_col(1, I) = I  % will work and is better form
    arr_one(I) = I  % will work and is better form


  • $\begingroup$ Thank you for hepling me @Matt B. Actually, the data in DefaultSC.Earth.SMA has 25 rows, they are not 25 columns. I have tried change to one-dimensional array, it still error. Then I did trial and error, and I found that DefaultSC.Earth.SMA is not an array. However it contains more than 1 data, GMAT read it as a variable. $\endgroup$ Commented Jan 31, 2021 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.