Creating callable function with prompts
3 views (last 30 days)
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!!
Adam Danz on 16 Jun 2022
Edited: Adam Danz on 16 Jun 2022
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.