![]() |
如何使用提示中的现有变量提示输入
我正在尝试向用户询问某个变量的值,但同时,向用户显示最后使用的值(在程序终止时,这些值将保存到文件中,并在开始时加载程序)。
像这样: [B][I]输入新的半径值(R = 12.6):[/I][/B] [I]...用户输入12.7 ...[/I] [B][I]输入新的pi值(pi = 3.14):[/I][/B] [B][I]输入新的高度值(h = 30.0):[/I][/B] 通常,我会使用[I]write[/I]语句编写第一个,然后[I]读取[/I]新语句(例如,在Fortran中)。但是在MATLAB中,我不知道如何用[I]输入[/I]语句写一些东西。还有其他获取输入的语句吗? [B]回答:[/B] 您可以将命令input与此sprintf结合使用。 %# set defaults radius = 12.6; %# ask for inputs tmp = input(sprintf('Enter new radius value (R=%4.2f)\n',radius)); %# if the user hits 'return' without writing anything, tmp is empty and the default is used if ~isempty(tmp) radius = tmp; end 或者,您可能需要研究[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/inputdlg.html"]INPUTDLG[/URL] [url=https://stackoverflow.com/questions/2794125]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 01:22。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.