필터 지우기
필터 지우기

How to enter data from a GUI (?) rather than in code.

조회 수: 1 (최근 30일)
Jonathan Pulman
Jonathan Pulman 2013년 11월 22일
댓글: Image Analyst 2013년 11월 23일
How can I start a program running then, at some point dictated by the code, ask for user input such as a number or a choice of "do this or do that". (I am not sure if it is a "GUI" that I am needing.) So far I only know how to input data through the code. Jonathan.

답변 (2개)

Walter Roberson
Walter Roberson 2013년 11월 22일
input() to ask from the command prompt. inputdlg() for graphical work.
  댓글 수: 2
Jonathan Pulman
Jonathan Pulman 2013년 11월 22일
Thank you Walter. I taught myself QBasic years ago but now it is obsolete. I find the very basic things in Matlab documentation hard to understand. Examples of code provided often contain in them other things which confuse me like "twister" concerning random numbers. I look up "random" then I see "twister" so then I am trying to understand "twister" and I go in circles.
It is hard to get info if I don't know the words to search for. Matlab is really superb but my lack of basic knowledge is a problem. I find the online community really helpful; one question here saves two hours of frustration. Thank you again, Jonathan.
Iain
Iain 2013년 11월 22일
uigetfile, uiputfile, & uigetdir will help too.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2013년 11월 22일
Here's a snippet. Feel free to modify:
% 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
  댓글 수: 2
Jonathan Pulman
Jonathan Pulman 2013년 11월 23일
This will be helpful. It is new for me but it looks like I will be able learn from it. New but not unintelligible!
Thank you. Jonathan.
Image Analyst
Image Analyst 2013년 11월 23일
If you want to take a look at a nice framework where most stuff is done for you, check this out: http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component. Please mark the best answer as "Accepted" (you can only mark one as such).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by