File name a function argument
조회 수: 8 (최근 30일)
이전 댓글 표시
Hello there,
I hope every body is doing file. I have two questions. I will be very grateful if any matlab advance user can reply me.
1. Could you please tell me how I can use file name (say, aba.txt, actually data in text file) as Argument in a Matlab Function?
2. Can I call .m file ( not function, just code) inside another .m file? If yes, could you please suggest me, how I can do that.
Thanks in advance Regards Shafi
댓글 수: 0
채택된 답변
Matt Fig
2011년 4월 2일
1. Which is it? Do you want to have the filename passed or the data in the file?
2. Do you mean that you want to call a script M-file as opposed to a function M-file? Simply put the name of the script wherever you would like to run it.
댓글 수: 0
추가 답변 (1개)
Matt Tearle
2011년 4월 2일
1. the standard approach would be to use a string
function y = foo(fname)
fid = fopen(fname);
etc
Then call it with
x = 'abc.txt';
y = foo(x);
2. yes, just give the name of the script (without the .m extension) as a command, just like you'd run it at the command line.
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!