i have an app and want a edit field to read in multiple double values and confirm with enter in matlab

You can create a graphical user interface (GUI) in MATLAB to input multiple double values using an edit field and confirm using the enter key. Here's an example of how you can achieve this:

main.m
function myApp
    % Create a figure window
    fig = figure('Position', [100 100 300 200], 'MenuBar', 'none', 'ToolBar', 'none');

    % Create an edit field
    editField = uicontrol('Style', 'edit', 'Position', [10 10 280 30], 'KeyPressFcn', @handleKeyPress);

    % Create a confirmation button
    confirmButton = uicontrol('Style', 'pushbutton', 'String', 'Confirm', 'Position', [110 60 80 30], 'Callback', @confirmValues);

    % Initialize an empty array to store the entered values
    inputValues = [];

    % Function to handle key press events in the edit field
    function handleKeyPress(src, event)
        if strcmp(event.Key, 'return')
            % Get the entered text from the edit field
            enteredText = get(src, 'String');
            % Convert the text to a double value
            enteredValue = str2double(enteredText);
            
            % If the conversion is successful, add the value to the inputValues array
            if ~isnan(enteredValue)
                inputValues = [inputValues enteredValue];
            end
            % Clear the edit field
            set(src, 'String', '');
        end
    end

    % Function to handle the button click event to confirm the entered values
    function confirmValues(~, ~)
        disp(inputValues);
    end
end
1306 chars
36 lines

Save the above code in a file with a .m extension and run the myApp function to start the application. The edit field will read in double values, and when the enter key is pressed, the values will be stored in the inputValues array. Clicking the "Confirm" button will display the entered values in the command window.

Note: This is a basic example to get you started. You can modify the code to suit your specific requirements and add error handling as necessary.

related categories

gistlibby LogSnag