input: Write a function to perform various matrix operations like addition, subtraction, multiplication, and transpose. The function should return a new matrix after each operation. If the given matrices are not compatible for an operation, return None. If the given input is empty, return None.
  assert matrix_operations([[1, 1], [2, 2]], [[2, 2], [3, 3]], 'add')==[[3, 3], [5, 5]]
  assert matrix_operations([[3, 4], [5, 6]], [[1, 2], [2, 3]], 'sub')==[[2, 2], [3, 3]]
  assert matrix_operations([[1, 2], [3, 4]], [[5, 6], [7, 8]], 'mul')==[[19, 22], [43, 50]]
  assert matrix_operations([[1, 2], [3, 4]], '', 'transpose')==[[1, 3], [2, 4]]
  assert matrix_operations([], [], 'add')==None
  assert matrix_operations([[1, 2], [3, 4]], [[1], [2]], 'mul')==None
output: def matrix_operations(matrix1, matrix2, operation):
      if not matrix1 or not matrix2:
          return None
      
      rows1, cols1 = len(matrix1), len(matrix1[0])
      rows2, cols2 = len(matrix2), len(matrix2[0])
      
      if operation == 'add':
          if rows1 != rows2 or cols1 != cols2:
              return None
          return [[matrix1[i][j] + matrix2[i][j] for j in range(cols1)] for i in range(rows1)]
      
      elif operation == 'sub':
          if rows1 != rows2 or cols1 != cols2:
              return None
          return [[matrix1[i][j] - matrix2[i][j] for j in range(cols1)] for i in range(rows1)]
      
      elif operation == 'mul':
          if cols1 != rows2:
              return None
          result = [[0 for _ in range(cols2)] for _ in range(rows1)]
          for i in range(rows1):
              for j in range(cols2):
                  for k in range(cols1):
                      result[i][j] += matrix1[i][k] * matrix2[k][j]
          return result
      
      elif operation == 'transpose':
          if matrix2:
              return None
          return [[matrix1[j][i] for j in range(rows1)] for i in range(cols1)]
      
      return None