diff --git a/dune/matrix-vector/algorithm.hh b/dune/matrix-vector/algorithm.hh
index 81d55f7ee8724d1051b80fd9826c91337a9042a7..c2d3605cc4505ab4b068d7e4b2bc6378b3fb918e 100644
--- a/dune/matrix-vector/algorithm.hh
+++ b/dune/matrix-vector/algorithm.hh
@@ -40,6 +40,15 @@ void sparseRangeFirst(Range&& range, F&& f)
   f(*range.begin());
 }
 
+template <class Matrix, class F>
+void sparseMatrixFor(Matrix&& m, F&& f) {
+  sparseRangeFor(m, [&](auto&& row, auto&& i) {
+    sparseRangeFor(row, [&](auto&& col, auto&& j) {
+      f(col, i, j);
+    });
+  });
+}
+
 } // namespace MatrixVector
 } // namespace Dune