Matlab comes with a built-in IP component, com.jidesoft.field.IPTextField, which is part of the JIDE library of components. You can use it as follows:
jIPField = com.jidesoft.field.IPTextField('255.255.255.0');
[jIPField, hContainer] = javacomponent(jIPField, [10,10,120,20], hParent);
You can modify the position/size of the text-field in the javacomponent call above, or by modifying the Position / Units properties of hContainer.
You can retrieve the IP text/numeric values using:
vals = jIPField.getValue';
vals = cell(jIPField.getRawText)';
ip = char(jIPField.getText);
The component auto-validates the IP values, ensuring that the displayed IP is always valid. The component has many other features, including the ability to enable/disable, color or format the IP components etc.
You can set a callback function to process user changes, by setting the component's StateChangedCallback property, for example:
jIPField.StateChangedCallback = @(jComponent,jEventData) disp(jComponent.getValue');
The JIDE libraries that come with Matlab contain numerous other similarly-useful components, including date/time selectors, credit-card fields, etc. etc.