I wrote a script in which it retrieves data from a database and i have given the option to the user whether they would like to search again. @Andrey helped me fix the problem with the user answering ‘Yes’ or ‘No’ to the question.
goAgain = true;
while goAgain
pdbSearch = input('Enter your PDB Code: ', 's');
curs = fetch(exec(conn, ['SELECT * FROM cath_2_wo_dup WHERE pdbcode = ' '''' pdbSearch '''']));
fprintf('Results Successful! \n');
results = curs.Data % prints the data out
% ----------------------
% User option to search again
% -----------------------
res = input('Would you like to search for another pdb?', 's');
goAgain = isequal(upper(res),'YES');
end
However, I have another query that i would like to ask. How do i allow the data that has been retrieved first to be displayed in the workspace, before giving the option to the user of searching again?
Although it shows the results in the command window, i would like to see my results that i have queried in the Variable Editor before searching again. It only displays the variables in the workspace after I have entered ‘No’ in the command window.
Please advise.
The workspace browser shows you the existing variables after you enter ‘No’ because that is when the while loop ends. If during execution of a script, function or, as in your case a loop, the browser is updated, this would be too expensive. And by expensive I mean CPU-intensive: just like if you use fprintf() in a loop…
If you want to play with the intermediate values, then set a break point at
and when the while-loop reaches there, you will see the workspace browser updated. I do not know if this helps you.
If you want to be able to browse previous choices after you enter ‘No’, then use a cell array to store the past search results:
end