Method for machining a workpiece, preferably consisting at least partially of wood, wood-based materials, plastic or the like, using a device for machining a workpiece preferably consisting at least partially of wood, wood-based materials, plastic or the like, comprising: at least one machining arrangement for machining the workpiece , a conveying arrangement for bringing about a relative movement between at least one machining arrangement and the workpiece , at least one contactless distance sensor which is configured to measure a distance from a surface of the workpiece , wherein the at least one contactless distance sensor is configured to measure the distance with a measurement accuracy of +/- 0.01 mm or more precisely, and/or has a triangulation sensor, with the steps: measuring the distance from the surface of the workpiece using the at least one contactless distance sensor , determining an actual position of the surface of the workpiece in relation to the machining arrangement based on the measured distance, setting a target position of the machining arrangement taking into account machining data, and machining the workpiece in the region of the surface, characterised in that several measured values are recorded along the surface of the workpiece by the at least one distance sensor , wherein measured values whose deviation in magnitude from a neighbouring measured value exceeds a predetermined threshold value are ignored when determining an actual position of the surface of the workpiece . at least one machining arrangement for machining the workpiece , a conveying arrangement for bringing about a relative movement between at least one machining arrangement and the workpiece , at least one contactless distance sensor which is configured to measure a distance from a surface of the workpiece , wherein the at least one contactless distance sensor is configured to measure the distance with a measurement accuracy of +/- 0.01 mm or more precisely, and/or has a triangulation sensor, with the steps: measuring the distance from the surface of the workpiece using the at least one contactless distance sensor , determining an actual position of the surface of the workpiece in relation to the machining arrangement based on the measured distance, setting a target position of the machining arrangement taking into account machining data, and machining the workpiece in the region of the surface, characterised in that several measured values are recorded along the surface of the workpiece by the at least one distance sensor , wherein measured values whose deviation in magnitude from a neighbouring measured value exceeds a predetermined threshold value are ignored when determining an actual position of the surface of the workpiece . measuring the distance from the surface of the workpiece using the at least one contactless distance sensor , determining an actual position of the surface of the workpiece in relation to the machining arrangement based on the measured distance, setting a target position of the machining arrangement taking into account machining data, and machining the workpiece in the region of the surface, characterised in that several measured values are recorded along the surface of the workpiece by the at least one distance sensor , wherein measured values whose deviation in magnitude from a neighbouring measured value exceeds a predetermined threshold value are ignored when determining an actual position of the surface of the workpiece . <EOS>