Using 2 MATLAB files to simulate 3 plots

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
PhysicsTruth
Messages
117
Reaction score
18
TL;DR
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?
 
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.
 
Reply
  • Like
Likes   Reactions: DrClaude