在MATLAB中询问是或否查询 [英] Asking a Yes or No query in MATLAB

查看:266
本文介绍了在MATLAB中询问是或否查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MATLAB中编写了一个脚本,我根据WHERE子句从表中检索行和列。到目前为止,我设法从数据库表中检索数据。

I have written a script in MATLAB, where I am retrieving rows and columns from a table based on the WHERE clause. So far i manage to retrieve the data from the database table.

问题是我想让用户可以选择运行另一个搜索来检索另一个数据集。

The problem is that i would like to allow the user to have the option of running another search to retrieve another set of data.

这是我的代码到目前为止我的代码和脚本被称为'searchpdb'。

This is my code so far that i have and the script is called 'searchpdb'.

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
% -----------------------

goAgain = input('Would you like to search for another pdb?', 's');
% if (goAgain = 'Yes')
if strcmp(goAgain, 'Yes')
    searchpdb(); %runs this script again.
elseif strcmp(goAgain, 'No')
    fprintf('\nBye!\n');

end

我尝试使用'questdlg',但它没有在我给用户选项再次运行之后显示表中数据的结果。

I have tried using 'questdlg', but it does not show the results of the data in the table after i have given the option to the user to run again.

我这样做是错误的,或者是否有另一种效率这样做的方式?是否应该再次运行脚本的选项在另一个脚本中?

I am doing this the wrong way, or is there another efficient way of doing it? Should the option of running the script again be in another script ?

推荐答案

嗯,它会起作用,但我建议使用子句而不是递归调用脚本:

Well, it will work, but I would recommend using a while clause instead of calling the script recursively:

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

对于您的代码的读者来说,这一点变得更加清晰。只要看看这个新代码的第一行,就可以猜到:

It just becomes clearer for the reader of your code. Just by taking a look at the first lines of this new code, one can guess that:


  1. 有一个循环 - 多次发生的事情。

  2. 有一个名为 goAgain 的停止条件。

  1. There is a loop - something happens multiple times.
  2. There is a stop condition called goAgain.

这篇关于在MATLAB中询问是或否查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆