MATLAB Answers

editing a string using GUI editable text/popup within guide

15 views (last 30 days)
I have a string, where I use strrep to replace a variable witha user input:
string = ('Today, I ate some (x)')
user_input = input('Enter your food: ', 's');
newstring = strrep('string', '(x)', user_input);
I want to use an editable textbox to get user_input. How would I do that?
My full script will have 3 editable textboxes, and 2 popups.
the popups will be changing a directory path, like I do here with sprintf:
user_input_food = input('enter food: ');
user_input_amount = input('enter amount: ');
root = 'C:\Users\Administrator';
% full path should look like C:\Users\Administrator\food\amount\food_amount.txt
filepath = fullfile(root, sprintf('food%s', user_input_food,), user_input_amount, sprintf('food%s_amount%s.txt', user_input_food, user_input_amount);
how do I get a popup menu to populate the user_input_experiment/user_input_squad variables?

Accepted Answer

Walter Roberson
Walter Roberson on 5 Dec 2019
user_input_food = handles.food_textbox.String; %assuming you named the edit uicontrol food_textbox
user_input_amount = handles.amount_textbox.String;
filepath = fullfile(root, sprintf('food%s', user_input_food), user_input_amount, sprintf('food%s_amount%s.txt', user_input_food, user_input_amount));
how do I get a popup menu to populate the user_input_experiment/user_input_squad variables?
If it is to be done according to computed content, then set the String property of the popup to a cell array of character vectors, one per line. Access the Value property to determine the index of which was selected. If you want to know the selected text, then for example,
experiment_choices = handles.experiment_popup.String;
user_choice = handles.experiment_popup.Value;
user_input_experiment = experiment_choices{user_choice};


Show 9 older comments
Walter Roberson
Walter Roberson on 11 Dec 2019
uiresume( ancestor(hObject, 'figure') )
into a buttondown function.
I do not recommend that. That risks the user accidentally triggering the function, such as if they click just outside an edit box because they are not being precise enough.
I recommend instead that you add a new button with a name such as 'Go' that does the work, moving all those things outside of the OutputFcn callback and into the Callback for the button. You would not use uiresume() if you did that. However, you might want to have the Go callback close the figure.
avram alter
avram alter on 11 Dec 2019
That's what I thought you meant. Populating the handles and then only actually running the importdata() at the user's behest. I will definitely try that, and update you. Thanks for the help so far, I really appreciate it.
avram alter
avram alter on 11 Dec 2019
that works perfectly, thanks for the help. If you have time, I posted a new question for a connected project. thanks so much.

Sign in to comment.

More Answers (0)

Sign in to answer this question.