Creating callable function with prompts

조회 수: 3(최근 30일)
Zain
Zain 2022년 6월 16일
댓글: Zain 2022년 6월 16일
This is pretty simple, but I'm new to MATLAB. I created a bunch of user prompts that will define variable names based on user inputs. I am struggling to find a way to define a function that initiates all the prompts for the user to answer but in another script. For example, I have this:
path_prompt = 'What is the file path?';
file_path = input(path_prompt);
name_prompt = 'What is the file name?';
file_name = input(name_prompt)
% and so on for a couple more variables
How could I put this inside a function to be called in a much bigger script and still have the user interact with the prompts? Thank you in advance!!
  댓글 수: 6
Zain
Zain 2022년 6월 16일
Makes sense. Thank you!

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

답변(1개)

Adam Danz
Adam Danz 2022년 6월 16일
편집: Adam Danz 2022년 6월 16일
Include the "S" in argument 2 to return the entered text without evaluating it.
> created a bunch of user prompts that will define variable names
Yikes! It sounds like you're describing Dynamic Variable Naming which is strongly not recommended. See this informative, epic rant for details. If you're planning on using the user input strings as variable names, don't do it.
Instead, you could store them in an array or, better yet, a table, along with the variable values within another column of the table.
  댓글 수: 5
Zain
Zain 2022년 6월 16일
I answered Carson's comment and I think that answers your first question as well. I'll try the table method. Thank you!

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by