フィルターのクリア

Is there any other function other than 'input' function in matlab to display prompts and waits for input

2 ビュー (過去 30 日間)
Since iam using matlab version 2010a,sometimes the function 'input'gets executed but all the times it is not executed...can anyone pls help me with this problem....
  1 件のコメント
Jan
Jan 2014 年 11 月 1 日
Please post a line of code, which fails and explain, what happens instead of your expectations.

サインインしてコメントする。

回答 (4 件)

Star Strider
Star Strider 2014 年 11 月 1 日
If your input call gets executed some times and not others, you likely have a logic problem in an if, while, or switch-case-otherwise block. Without seeing your code, it is impossible to say what the problem is.
Instead of input, I use the inputdlg function and its friends. It is much more efficient to use (in my opinion) than input, and does not clutter the Command Window. It should be available in R2010a

Abhinav
Abhinav 2014 年 11 月 1 日
編集済み: Abhinav 2014 年 11 月 1 日
you can use sprintf function. Then storing the variable value in other variable
  4 件のコメント
Abhinav
Abhinav 2014 年 11 月 6 日
編集済み: Image Analyst 2014 年 11 月 6 日
g=sprintf('press"C" and enter to conitnue' )
x=input(g,'s');
m=2
Image Analyst
Image Analyst 2014 年 11 月 6 日
But he asked "Is there any other function other than 'input' function in matlab to display prompts and waits for input" so he didn't want input() and that's why Star and I suggested inputdlg().

サインインしてコメントする。


Jan
Jan 2014 年 11 月 1 日
The command input works correctly in Matlab 2010a. So if you have any problems with it, there is a problem with anything else. As long as you do not describe the problem with any details and do not post some code, which demonstrates the problem, the reasons can be guessed only.
My guess: Perhaps you used "input" as a name of a variable before?
reply = input('Type in a number: '); % Works
input = rand(5);
reply = input('Type in another number: '); % Fails

Image Analyst
Image Analyst 2014 年 11 月 1 日
I use inputdlg all the time. Here's a snippet:
% Ask user for a number.
defaultValue = 45;
titleBar = 'Enter a value';
userPrompt = 'Enter the integer';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Round to nearest integer in case they entered a floating point number.
integerValue = round(str2double(cell2mat(caUserInput)));
% Check for a valid integer.
if isnan(integerValue)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
integerValue = defaultValue;
message = sprintf('I said it had to be an integer.\nI will use %d and continue.', integerValue);
uiwait(warndlg(message));
end
Depending on what kind of input you need, you might also be able to use questdlg() and menu().

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by