Using 2 MATLAB files to simulate 3 plots

Click For Summary
SUMMARY

The discussion focuses on using two MATLAB files to generate three plots in MATLAB Online. Users must place both the main file and the helper .m file in the same folder within MATLAB Drive. If the helper file is a function that returns a value, it should be called within the main file using the syntax c = helping(a, b);. If it is a script or a function that does not return a value, it can be called simply by its name.

PREREQUISITES
  • Basic understanding of MATLAB syntax and file structure
  • Familiarity with MATLAB Drive for file management
  • Knowledge of function and script file distinctions in MATLAB
  • Ability to interpret MATLAB code for plotting
NEXT STEPS
  • Learn how to manage files in MATLAB Drive effectively
  • Explore MATLAB function creation and calling conventions
  • Study MATLAB plotting functions to enhance visualization skills
  • Investigate debugging techniques for MATLAB scripts and functions
USEFUL FOR

Beginners in MATLAB, students learning programming concepts, and anyone interested in data visualization using MATLAB.

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?
 
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.
 
  • Like
Likes   Reactions: DrClaude

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K