MATLAB Answers


Access to a file when running the program

Hello, i have to files .m in the same folder. One is used to run the main program and the other is used just to put the information input for the program.


one file is the main.m and the other is info.m

info.m is similiar to this:

Volume_inicial = 900000000; Volume_final = 900000000; Volume_min = 800000000; Volume_max = 1000000000; Caudal_turb_max = 400; Caudal_bomb_max = 400;

Now, in the main.m i wanna be able to pick this data. How can i pick just Volume_inicial p.e?



No tags are associated with this question.


No products are associated with this question.

2 Answers

Answer by Muruganandham Subramanian on 14 Dec 2012
Edited by Muruganandham Subramanian on 14 Dec 2012
 Accepted answer

Or You can declare as global variable like global Volume_inicial in your info.m file

and if you want to access particular file info, use open() command

e.g. open(D:\Users\programfiles\myfolder\info.m')



If %condition satisfies


or you can use *while() *also else end

Its a possible solution. Thanks!

on 14 Dec 2012

This is not a good idea, I would even say terrible. You can just call one script from another.

Main.m could look like this:

 %Hi, I am main
 %Load your data
 %Do your stuff

Note that once you load your info, you can save it to other variables and could even do this dynamically

If you want to get fancier, look at the run() command

Answer by Vishal Rane
on 14 Dec 2012

You could simply run the other file, thus loading its contents in the workspace and use any variables you need.

  1 Comment

That works, but the problem is that i have 4 info files. info1, info2, info3 and 4. They all have the same type of information but the values are different. If i load its contents into the workspace i won't be able to differentiate them and it will give me the value from the 1st file i load.

By the way, is it possible to make a while cicle to call the different info files based on their number?

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!