rgj
rgj

Reputation: 125

Ask for user input initially, but immediately proceed with remaining code without waiting for answer

I'm analyzing several different data sets that individually take a while to process. I need to input a bunch of information for each set of data, but the info itself (series of strings) is arbitrary and unimportant to the analysis. To save time overall, I want to present all the input fields initially, but not have the code wait for me to finish filling all the info in before proceeding with the analysis. Hopefully the example code below clarifies my objectives.

%%%% Best code ever

% Select data file
filename = uigetfile

% Ask for information related to data set
info1 = input('Info1? = ','s');
info2 = input('Info2? = ','s');

% Load data and begin analysis without waiting for user response to inputs above
pause(1); % arbitrary time intensive process

% More code to display/save after inputs are entered data analysis finishes
plot(x,y)

%%%%

I had issues with searching for similar topics because the only keyword/phrase I could come up with was "parallel processes" but that seemed to open a much more complex can of worms. The only luck I had was here, but it seemed too specific and I got lost since my coding abilities are casual at best...

Upvotes: 3

Views: 82

Answers (1)

Thomas Ibbotson
Thomas Ibbotson

Reputation: 745

MATLAB's interpreter is single-threaded, which means you can only do one thing at a time. I think your best option would be to create a GUI (perhaps with GUIDE) for inputting the information, which the user could interact with while the other code was running. I'm afraid this is essentially the same solution as proposed in the question you linked to, I don't think there's a much easier way to do this.

Upvotes: 2

Related Questions