MATLAB Using 2 MATLAB files to simulate 3 plots

AI Thread Summary
To run a main MATLAB file that calls a helper .m file, both files must be stored in the same folder within MATLAB Drive when using MATLAB online. If they are in different folders, the other folder must be added to the MATLAB path. If the helper file is a function that returns a value, it should be called from the main file using the syntax "c = helping(a, b);" where 'a' and 'b' are input parameters. If the helper file is a script or a function without return values, it can be called simply by its name. For further assistance, sharing the contents of the files, particularly how the helper file is called in the main file, can provide clarity.
PhysicsTruth
Messages
117
Reaction score
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
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:
[CODE lang="matlab" title="main_file.m" highlight="3"]a = 2;
b = 3;
c = helping(a, b); % This is how you call a function
d = a + b + c;[/CODE]
If helping is a simple script file, or a function file that does not return anything, simply call it by it's name:
[CODE lang="matlab" title="main_file.m" highlight="3"]a = 2;
b = 3;
helping;
d = a + b;[/CODE]
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.
 
Back
Top