Access to a file when running the program

조회 수: 1 (최근 30일)
André Pacheco
André Pacheco 2012년 12월 14일
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.
p.e:
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?

채택된 답변

Muruganandham Subramanian
Muruganandham Subramanian 2012년 12월 14일
편집: Muruganandham Subramanian 2012년 12월 14일
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')
  댓글 수: 3
André Pacheco
André Pacheco 2012년 12월 14일
Its a possible solution. Thanks!
José-Luis
José-Luis 2012년 12월 14일
편집: José-Luis 2012년 12월 14일
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
info
%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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Vishal Rane
Vishal Rane 2012년 12월 14일
You could simply run the other file, thus loading its contents in the workspace and use any variables you need.
  댓글 수: 1
André Pacheco
André Pacheco 2012년 12월 14일
편집: André Pacheco 2012년 12월 14일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by