How to input a value from a table and get corresponding values from the row
2 views (last 30 days)
Show older comments
My goal is prompt the user to input a value from the first column of a table and get an output for the rest of the row.
0 Comments
Answers (1)
Image Analyst
on 21 Sep 2014
data = get(handleToTable, 'data');
restOfRows = data(2:end, 1); Get rows 2 through the bottom in column 1.
1 Comment
Image Analyst
on 21 Sep 2014
To prompt the user, you can use inputdlg(). See the examples in the help.
% 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
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!