Using 2 MATLAB files to simulate 3 plots

In summary, as an absolute beginner in MATLAB, you have two MATLAB files - a main file and a helping .m file. You need to run the main file in order to obtain 3 plots. To simulate this in your online MATLAB handle, you need to put both files in the same folder in MATLAB Drive. If the helping.m file is a function, you can call it within the main file using the appropriate syntax. If it is a simple script or a non-returning function, you can call it by its name. If you need further assistance, you can provide the contents of the files for more help.
  • #1
PhysicsTruth
117
18
TL;DR Summary
I'm a beginner in MATLAB and I want some help regarding how to activate a main file which calls another file within it in MATLAB online.
First of all, I'm an absolute beginner in MATLAB.

Secondly, I have 2 MATLAB files, one entitled as a "main file" and the other one as a helping .m file, which is called by the main file. I need to run the main file in order to obtain 3 plots. What is the exact procedure that I should follow in my online MATLAB handle to simulate these? Do I need to add both files under the same folder? Can someone guide me through these?
 
Physics news on Phys.org
  • #2
PhysicsTruth said:
online MATLAB handle
You mean, you are using MATLAB online? Then you need to put both files in MATLAB Drive, under the same folder. You can put them under different folders too, but then you need to add the other folder to the path.

If the helping.m is a function file that returns something, then you simply need to call it within main_file.m as follows:
main_file.m:
a = 2;
b = 3;
c = helping(a, b); % This is how you call a function
d = a + b + c;
If helping is a simple script file, or a function file that does not return anything, simply call it by it's name:
main_file.m:
a = 2;
b = 3;
helping;
d = a + b;
If anything is unclear, I can provide more help if you post the contents of the two files, especially the part in the main_file.m where you are calling helping.m.
 
  • Like
Likes DrClaude

What is MATLAB?

MATLAB is a programming language and software environment commonly used by scientists and engineers to perform data analysis, mathematical calculations, and create visualizations.

What is a MATLAB file?

A MATLAB file, also known as a .m file, is a text file that contains code written in the MATLAB language. It is used to store and execute MATLAB commands and functions.

How do I use 2 MATLAB files to simulate 3 plots?

First, you will need to create two separate .m files, each containing the code for one of the plots you want to simulate. Then, in a new .m file, you can call the functions from the first two files and plot them using the plot() function. You can use the hold on or hold off commands to plot multiple graphs on the same figure.

What are the benefits of using MATLAB for simulation?

MATLAB has a user-friendly interface and a wide range of built-in functions and tools that make it easy to simulate and visualize data. It also has powerful mathematical capabilities and the ability to handle large data sets, making it ideal for scientific and engineering simulations.

Can I customize the plots in MATLAB?

Yes, MATLAB allows for extensive customization of plots, including changing the colors, line styles, axes labels, and adding titles and legends. You can also adjust the plot size, layout, and resolution to meet your specific needs.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top