Saving Matrices in Matlab to Computer

Sometimes you need to save matrices in Matlab. For example, you created a matrix according to data that you are collecting in Matlab, what you need to do is save the data that you collected as a matrix file. You can load this saved matrix whenever you want. The extension of the matrix is .mat. In this article, we will show you how to save matrices created in Matlab®.

How to Save and Load a Matrix in Matlab?

>> A(1,1)=1;
A(1,2)=3;
A(1,3)=5;
A(2,1)=7;
A(2,2)=8;
A(2,3)=11;
A(3,1)=100;
A(3,2)=1;
A(3,3)=4

A =

     1     3     5
     7     8    11
   100     1     4

>> 

For example, we want to save the created matrix above as “Factors” to the D: directory. Type “save D:\Factors” then press enter. You will save this matrix to the D: directory with the name “Factors”.

>> A(1,1)=1;
A(1,2)=3;
A(1,3)=5;
A(2,1)=7;
A(2,2)=8;
A(2,3)=11;
A(3,1)=100;
A(3,2)=1;
A(3,3)=4

A =

     1     3     5
     7     8    11
   100     1     4

>> save D:/Factors

We wrote the save function for this matrix in Matlab then we pressed Enter.

You have saved The Factors matrix file as the red arrow above. You can open this by typing “load D:\Factors” and then press enter to load it in Matlab.

As you can see, we typed “load D:\Factors” to the command window in Matlab, then we opened the related matrix at Workspace as the red arrow above.

Conclusion

The saving and loading of a matrix in Matlab are simple like that.

Do not forget to leave your comments and questions below about this topic.

If you want further coding examples about this topic, inform us in the comments.

We prepare this article for completely educative and informative purposes. Images used courtesy of Matlab®.

Your precious feedbacks are very important to us.

Above the saving matrices in Matlab, Matlab provides various kinds of useful tools and functions that you can use. You can see the examples of them below.

Partial Fractional Representation of Transfer Functions in Matlab®

Conversion Zero-Pole Gain Transfer Function to Polynomial in Matlab®

Generating Test Input Signals in MatLab®

Conversion of a Transfer Function to Zero-Pole Gain Form in Matlab®

Step Response of a Transfer Function in Matlab

Comments


Leave a Reply

Your email address will not be published. Required fields are marked *