필터 지우기
필터 지우기

Input .txt file to .exe in Matlab

조회 수: 2 (최근 30일)
Dian
Dian 2013년 6월 17일
Hai everyone.. I want to input .txt file or to Fortran .exe file in Matlab.. How could I solve this problem? My .exe file can running in Matlab but I can't input .txt file in Matlab.. For simple ex:
program tes
integer, parameter :: N = 5
real, dimension(1:N) :: x
real :: y
open (unit=1, file='data.txt')
do i = 1,N
read (unit=1, fmt=*) x(i)
y=x(i)+y
end do
close(unit=1)
print*,'y=',y
end program
If I run this .exe file, this program only can run file when I compiled but how do if I want to input other .txt file into this program.. Further, I will make GUI for this program..
Thank you, for your help..
  댓글 수: 1
Jan
Jan 2013년 6월 17일
This forum offers the possibility to forma your code. Obviously this would improve the readability of your code very much.

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

답변 (2개)

David Sanchez
David Sanchez 2013년 6월 17일
You can try to add uigetfile to your code:
[filename, pathname] = uigetfile('*.txt', 'Pick your text file');
This will launch a selection window where the user can retrieve a .txt of hher/his choosing.
  댓글 수: 1
Walter Roberson
Walter Roberson 2013년 6월 17일
You would also have to copy the user's .txt file into 'data.txt' in the directory you started up the Fortran program from.

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


Walter Roberson
Walter Roberson 2013년 6월 17일
If you remove the open and close, and you change the unit number to 5, then the program would be able to read from standard input. For example, your MATLAB routine might code:
[filename, pathname] = uigetfile('*.txt', 'Pick your text file');
fullname = fullfile(pathname, filename);
cmd = ['tes < ', fullname];
system(cmd);
  댓글 수: 2
Dian
Dian 2013년 6월 18일
this code can open other file. But in situation I want run other file into my .exe Fortran file, this can't solve my problem.. My .exe fortran file just run file .txt when I compiled before, but how if I want to use other .txt file?
Walter Roberson
Walter Roberson 2013년 6월 18일
Perhaps you overlooked the part where I wrote "If you remove the open and close, and you change the unit number to 5" ? Those changes would remove any dependence on a particular file name, and would instead have the code read from standard input.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by