[Matlab] How to save the obtained values.

  • MATLAB
  • Thread starter hurryon
  • Start date
  • Tags
    Matlab
In summary, to save your data in Matlab, you can use the save command and specify the name of the file and the variables you want to save. You can also specify the format in which you want to save your data, such as CSV or text. To load saved data, use the load command and specify the file name. It is possible to save only a specific part of your data using indexing. You can also save your data in a different location by specifying the desired path in the save command.
  • #1
hurryon
9
2
Hi, all.

I have performed some simulations in where random variables are used. Through the simulations, I got the final results as well as some figures. Here, I have a question. The obtained results and figures are based on the calculation with randomly created values. If I perform again with the same code, I'll get different results and figures. Thus, I'd like to save the current random values. How to save these ones?

I think that other folks might have similar experiences with me.

Thanks in advance.
 
Physics news on Phys.org
  • #3


I would recommend using the "save" function in Matlab to save the obtained values. This function allows you to save variables and figures in a .mat file, which can be easily loaded and accessed later on. You can also specify a file name for the saved values to keep track of your simulations. Additionally, you can use the "rng" function to control the random number generator in Matlab, allowing you to reproduce the same random values for your simulations. This will ensure consistency in your results and figures. I hope this helps.
 

1. How do I save my data in Matlab?

To save your data in Matlab, you can use the save command. This command allows you to specify the name of the file and the variables you want to save. For example, if you want to save a variable named "myData" in a file called "data.mat", you would use the command save('data.mat', 'myData').

2. Can I save my data in a specific format in Matlab?

Yes, you can specify the format in which you want to save your data using the save command. For example, if you want to save your data in a CSV format, you would use the command save('data.csv', 'myData', '-ascii'). You can also save your data in other formats such as text, Excel, or binary.

3. How do I load saved data in Matlab?

To load saved data in Matlab, you can use the load command. This command allows you to specify the name of the file from which you want to load the data. For example, if you saved your data in a file called "data.mat", you would use the command load('data.mat'). This will load all the variables stored in the file into your workspace.

4. Is it possible to save only a specific part of my data in Matlab?

Yes, you can save only a specific part of your data in Matlab using the save command. You can use indexing to specify which part of your data you want to save. For example, if you have a matrix named "myMatrix" and you want to save only the first 10 rows and columns, you would use the command save('data.mat', 'myMatrix(1:10, 1:10)').

5. How do I save my data in a different location in Matlab?

By default, Matlab saves your data in the current working directory. However, you can specify a different location to save your data using the save command. For example, if you want to save your data in a folder called "myData" on your desktop, you would use the command save('C:\Users\username\Desktop\myData\data.mat', 'myData').

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
858
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
741
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
992
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
808
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
Back
Top