class_docstr: Generic matlab matrix writing class 
docstr: Write string array `arr` with given `codec`
          
docstr_tok: ["Write","string","array","`","arr","`","with","given","`","codec","`"]
code: def write_char(self, arr, codec="ascii"):
      """Write string array `arr` with given `codec`"""
      if arr.size == 0 or np.all(arr == ""):
          # This an empty string array or a string array containing
          # only empty strings. Matlab cannot distinguish between a
          # string array that is empty, and a string array containing
          # only empty strings, because it stores strings as arrays of
          # char. There is no way of having an array of char that is
          # not empty, but contains an empty string. We have to
          # special-case the array-with-empty-strings because even
          # empty strings have zero padding, which would otherwise
          # appear in matlab as a string with a space.
          shape = (0,) * np.max([arr.ndim, 2])
          self.write_header(shape, mxCHAR_CLASS)
          self.write_smalldata_element(arr, miUTF8, 0)
          return
      # non-empty string.
      #
      # Convert to char array
      arr = arr_to_chars(arr)
      # We have to write the shape directly, because we are going
      # recode the characters, and the resulting stream of chars
      # may have a different length
      shape = arr.shape
      self.write_header(shape, mxCHAR_CLASS)
      if arr.dtype.kind == "U" and arr.size:
          # Make one long string from all the characters. We need to
          # transpose here, because we're flattening the array, before
          # we write the bytes. The bytes have to be written in
          # Fortran order.
          n_chars = np.prod(shape)
          st_arr = np.ndarray(
              shape=(),
              dtype=arr_dtype_number(arr, n_chars),
              buffer=arr.T.copy(),
          )  # Fortran order
          # Recode with codec to give byte string
          st = st_arr.item().encode(codec)
          # Reconstruct as 1-D byte array
          arr = np.ndarray(shape=(len(st),), dtype="S1", buffer=st)
      self.write_element(arr, mdtype=miUTF8)
  
imports: import os
  import time
  import sys
  import zlib
  from io import BytesIO
  import warnings
  import numpy
  import scipy.sparse
  from .byteordercodes import native_code, swapped_code
  from .miobase import MatFileReader, docfiller, matdims, read_dtype, arr_to_chars, arr_dtype_number, MatWriteError, MatReadError, MatReadWarning
  from .mio5_utils import VarReader5
  from .mio5_params import MatlabObject, MatlabFunction, MDTYPES, NP_TO_MTYPES, NP_TO_MXTYPES, miCOMPRESSED, miMATRIX, miINT8, miUTF8, miUINT32, mxCELL_CLASS, mxSTRUCT_CLASS, mxOBJECT_CLASS, mxCHAR_CLASS, mxSPARSE_CLASS, mxDOUBLE_CLASS, mclass_info, mat_struct
  from .streams import ZlibInputStream
label_desc: Use image node_id 12 for calling the VarWriter5 obj's underlying member method code with example usage: obj.write_char(arr, codec) without return types