フィルターのクリア

Pass text file as argument to function?

3 ビュー (過去 30 日間)
Janell Lopez
Janell Lopez 2016 年 9 月 25 日
コメント済み: Janell Lopez 2016 年 9 月 26 日
Hi,
I have a homework assignment where we have a main function that calls 3 other functions: one reads a system of equations from a text file, one solves the system, and one writes the system and its solutions to a new text file. I'm supposed to pass the name of the text file as the argument to the main function (or have the user be able to do so) so that I don't have to modify the code at all to be able to read from different text files. Right now I have a script instead of a function for the main function, and everything works if you modify the name of the text file in the code. How do I change it so that I can call the function with the text file as the argument? Do you pass it as a string? How do I call the subfunctions within the main function with a text file name as an argument?
Thank you!

採用された回答

Image Analyst
Image Analyst 2016 年 9 月 25 日
Let's say your main function is called main.m and it's a script right now. Simply put this line at the first line of that main.m file:
function main(fullFileName)
then inside the function call fgetl() or whatever you want. But then to pass the string into main, you're going to have to call uigetfile() either from the command line, or from another script or function.
  1 件のコメント
Janell Lopez
Janell Lopez 2016 年 9 月 26 日
Thanks that's what I needed!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by