@magic_arguments()
    @argument(
        '-i', '--input', action='append',
        help='Names of input variable from shell.user_ns to be assigned to Matlab variables of the same names after calling self.pyconverter. Multiple names can be passed separated only by commas with no whitespace.'
        )

    @argument(
        '-o', '--output', action='append',
        help='Names of variables to be pushed from matlab to shell.user_ns after executing cell body and applying self.Matlab.get_variable(). Multiple names can be passed separated only by commas with no whitespace.'
        )

    @argument(
        '-s', '--silent', action='store_true',
        help='Do not display text output of MATLAB command'
        )

    @argument(
        '-S', '--size', action='store', default='512,384',
        help='Pixel size of plots, "width,height.'
    )

    @argument(
        '-g', '--gui', action='store_true',
        help='Show plots in a graphical user interface'
    )

    @argument(
        'code',
        nargs='*',
        )


    @needs_local_scope
    @line_cell_magic
    def matlab(self, line, cell=None, local_ns=None):
        "Execute code in matlab."

        args = parse_argstring(self.matlab, line)
        code = line if cell is None else ' '.join(args.code) + cell

        if local_ns is None:
            local_ns = {}

        width, height = args.size.split(',')
        self.Matlab.set_plot_settings(width, height, not args.gui)

        if args.input:
            for input in ','.join(args.input).split(','):
                try:
                    val = local_ns[input]
                except __HOLE__:
                    val = self.shell.user_ns[input]
                # The _Session.set_variable function which this calls
                # should correctly detect numpy arrays and serialize them
                # as json correctly.
                self.set_matlab_var(input, val)

        try:
            result_dict = self.eval(code)
        except MatlabInterperterError:
            raise
        except:
            raise RuntimeError('\n'.join([
                "There was an error running the code:",
                code,
                "-----------------------",
                "Are you sure Matlab is started?",
            ]))

        text_output = result_dict['content']['stdout']
        # Figures get saved by matlab in reverse order...
        imgfiles = result_dict['content']['figures'][::-1]
        data_dir = result_dict['content']['datadir']

        display_data = []
        if text_output and not args.silent:
            display_data.append(('MatlabMagic.matlab',
                                 {'text/plain': text_output}))

        for imgf in imgfiles:
            if len(imgf):
                # Store the path to the directory so that you can delete it
                # later on:
                with open(imgf, 'rb') as fid:
                    image = fid.read()
                display_data.append(('MatlabMagic.matlab',
                                     {'image/png': image}))

        for disp_d in display_data:
            publish_display_data(source=disp_d[0], data=disp_d[1])

        # Delete the temporary data files created by matlab:
        if len(data_dir):
            rmtree(data_dir)

        if args.output:
            for output in ','.join(args.output).split(','):
                self.shell.push({output:self.Matlab.get_variable(output)})
dataset/ETHPy150Open arokem/python-matlab-bridge/pymatbridge/matlab_magic.py/MatlabMagics.matlab