关于gui计算器的小疑问

下午好,我用matlab做了一个简易的gui计算器。然而我现在想要自动阻止计算器在一个数字中键入两个小数点这类功能,我应该怎么做

该回答引用GPT

function editbox_Callback(hObject, eventdata, handles)
% hObject    handle to editbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get the current text in the edit box
input_str = get(hObject, 'String');

% Check if the input string already contains a decimal point
if any(input_str == '.')
    % If a decimal point is already present, remove any additional ones
    input_str = strrep(input_str, '.', '');
    set(hObject, 'String', input_str);
end

% Store the updated input string in the app data
setappdata(handles.figure1, 'input_str', input_str);

你需要将该回调函数与你的GUI中的编辑框关联。在 MATLAB 中,你可以使用 GUIDE 工具来创建 GUI 并将回调函数分配给不同的 UI 组件。