How to enter data from a GUI (?) rather than in code.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (2)
Walter Roberson
el 22 de Nov. de 2013
input() to ask from the command prompt. inputdlg() for graphical work.
2 comentarios
Image Analyst
el 22 de Nov. de 2013
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 comentarios
Image Analyst
el 23 de Nov. de 2013
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).
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!