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 (10, 12) for machining the workpiece, a conveying arrangement for bringing about a relative movement between at least one machining arrangement (10, 12) and the workpiece, at least one contactless distance sensor (20, 22, 24, 26) which is configured to measure a distance from a surface of the workpiece, wherein the at least one contactless distance sensor (20, 22, 24, 26) 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 (20, 22, 24, 26), determining an actual position of the surface of the workpiece in relation to the machining arrangement (10, 12) based on the measured distance, setting a target position of the machining arrangement (10, 12) 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 (20, 22, 24, 26), 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 (10, 12) for machining the workpiece, a conveying arrangement for bringing about a relative movement between at least one machining arrangement (10, 12) and the workpiece, at least one contactless distance sensor (20, 22, 24, 26) which is configured to measure a distance from a surface of the workpiece, wherein the at least one contactless distance sensor (20, 22, 24, 26) 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 (20, 22, 24, 26), determining an actual position of the surface of the workpiece in relation to the machining arrangement (10, 12) based on the measured distance, setting a target position of the machining arrangement (10, 12) 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 (20, 22, 24, 26), 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 (20, 22, 24, 26), determining an actual position of the surface of the workpiece in relation to the machining arrangement (10, 12) based on the measured distance, setting a target position of the machining arrangement (10, 12) 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 (20, 22, 24, 26), 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.