Variable feeding into a function

조회 수: 5 (최근 30일)
Yewande Oni
Yewande Oni 2015년 9월 3일
댓글: Star Strider 2015년 9월 3일
How can I get a variable from one script to feed into a function? Hope that makes sense?

채택된 답변

Star Strider
Star Strider 2015년 9월 3일
If the function is in its own function .m-file in your MATLAB search path, just call the function in your script with that variable as an argument to the function, just as you would any other function.
  댓글 수: 2
Yewande Oni
Yewande Oni 2015년 9월 3일
Ops! I didn't meant to accept the answer.
What I meant is, my function uses xlsread but the filename is a variable entered from another script. When that filename has been entered, how can I feed that into my function? Thanks
Star Strider
Star Strider 2015년 9월 3일
Thank you anyway!
I don’t quite understand what you’re doing. It might be easiest to call your function from the script that creates the filename and pass the filename as an argument to the function.
If the function really isn’t a function but is instead another script, the easiest way I can think of just now is to write the filename to a .mat file with a specific name, then have your other script read that .mat file and get the name from it. That’s how I would do it (but then my code isn’t always as efficient as it could be).

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

추가 답변 (0개)

카테고리

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