m2ipynb

m2ipynb convert selected m files into Jupyter notebook files

Syntax

Description

m2ipynb transforms m files which have a predefined label first into mlx files and then into Jupiter notebook files. This file also automatically appends inside README.md files a table written in markup language. To understand how this table looks like see https://github.com/UniprJRC/FigMonitoringBook/tree/main/cap1 or https://github.com/UniprJRC/FigMonitoringBook/tree/main/cap2 or https://github.com/UniprJRC/FigMonitoringBook/tree/main/cap33 or every other chapter in the book

example

Incl =m2ipynb() m2ipynb with all default options.

example

Incl =m2ipynb(Name, Value) As before but do not run the mlx files.

example

[Incl, Excluded] =m2ipynb(___) Example 1 of the use of option dirpath.

Examples

expand all

  • m2ipynb with all default options.
  • Convert first to .mlx and then to .ipynn all .m files in the current folder which contain 'InsideREADME' and append the table to README.md

    out=m2ipynb();

  • As before but do not run the mlx files.
  • out=m2ipynb('run',false);

  • Example 1 of the use of option dirpath.
  • In this case dipath is a character associated with a single .m file Just convert file whose name is 'rescaleFS.m'

    InclDir='rescaleFS.m';
    try
    out=m2ipynb('dirpath',InclDir);
    catch
    %disp(lasterror)
    emsg='Function m2ipynb has been called on a file which does not exist';
    MException('FSDA:m2ipynb:WrongInputOpt',emsg)
    end

    Related Examples

    expand all

  • Example 2 of the use of option dirpath.
  • In this case dipath is a cell which identifies a particular subfolder whose .m files have to be converted to .ipynb.

    InclDir={'cap1'};
    try
    out=m2ipynb('dirpath',InclDir);
    catch
    %disp(lasterror)
    emsg='Function m2ipynb has been called on a subfolder which does not exist';
    MException('FSDA:m2ipynb:WrongInputOpt',emsg)
    end

  • Example 3 of the use of option dirpath.
  • % Preliminary call to findDir Include all subfolderw whose name starts with cap or whose name is solutionsEX

    InclDir={'cap*' 'solutionsEX'};
    % Remove all subfolders whose names are 'AnalysisByDataset' or
    %  'IncomeDatasets' whose name starts with fig or with Fig5 or with
    %  exercises
    ExclDir = {'AnalysisByDataset' 'IncomeDatasets' 'fig*' 'Fig5*' 'exercises*'};
    % dirpath contains 
    dirpath=findDir(pwd,'InclDir',InclDir,'ExclDir',ExclDir);
    [Incl,Excl]=m2ipynb('run',false,'dirpath',dirpath);

    Input Arguments

    expand all

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: 'append2README',false , 'CatchError',false , 'category','##myPersonalLabel##' , 'deleteMLXfiles',true , 'dirpath',pwd , 'FilterOutFileName','veryold' , 'msg',false , 'printOutputCell','ContentsAll.m' , repoName 'github/awesome-matlab' , 'run',false , 'runExcluded','UserInteraction'

    append2README —append or not the list of filtered files to README.md file.

    Boolean. By default the list of filtered files in the specififed folder will be appended to the README.md file. If this table already exists inside the README.md, it will be replaced with the current one.

    Example: 'append2README',false

    Data Types: logical

    CatchError —Whether to catch errors.boolean.

    Whether to catch errors when running the live script or function during conversion, specified as a numeric or logical 1 (true) or 0 (false). If CatchError is true and an error occurs, export includes the error in the converted file. If CatchError is false and an error occurs, export displays the error in the Command Window and does not create a converted file.

    Example: 'CatchError',false

    Data Types: logical

    category —label inside the files which have to be translated into ipynb format.charater | string.

    As default all .m files which contain the label '%InsideREADME' will be converted into mlx format and later into ipynb format.

    They will also be included in the table inside the README.md file

    Example: 'category','##myPersonalLabel##'

    Data Types: character or string

    deleteMLXfiles —delete or not the .mlx files after their conversion to jupiter notebook format.

    Boolean. The default is false, that is .mlx are note deleted after their conversion to ipynb format.

    Example: 'deleteMLXfiles',true

    Data Types: logical

    dirpath —path to use or file to convert.cell array of characters | character.

    Absolute path of the folder(s) for which m2ipynb files must be created.

    If dirpath is not specified or it is empty all .m files in the current folder with the category label will be converted. If dirpath is a cell array of characters then .m file are converted for all specified subfolders.

    If dirpath is a charater containing a single file in the current folder, just this file will be converted.

    Remark: dirpath can be conveniently created with function findDir

    Example: 'dirpath',pwd

    Data Types: cell array of characters or char

    FilterOutFileName —filter files depending on their name.character | String.

    Character or string which specifies which .m files do not have to be included inside NameOutputFile. All files whose name contains FilterOutFileName will not be included inside NameOutputFile.

    If this optional argument is not specified all files containing string [OlD] (lower case or uppercase) will not be considered

    Example: 'FilterOutFileName','veryold'

    Data Types: string

    msg —It controls whether to display or not messages on the screen.boolean.

    If msg==false (default) messages are not displayed on the screen about all .m files which are considered for translation to ipynb

    Example: 'msg',false

    Data Types: logical

    printOutputCell —print output cell in the screen.boolean.

    If printOutputCell folder which contains the summary of all files present in findDir folders. The default value of printOutputCell is '' that is the overall content file is not created

    Example: 'printOutputCell','ContentsAll.m'

    Data Types: string

    repoName —GitHub repository name.character | string.

    String which the GitHub repository address The default is to use 'UniprJRC/FigMonitoringBook'

    Example: repoName 'github/awesome-matlab'

    Data Types: Character or string

    run —Whether to run the code in the .mlx files include outputs.

    Boolean.

    If this option is set to true (default) the code inside the MLX files is run and the output is included in the converted file. Through option runExcluded it is possible to control the files which have to be translated to ipynb format with run set to false.

    Example: 'run',false

    Data Types: logical

    runExcluded —String which identifies files with run set to false.'Character' | 'string'.

    The default of runExcluded is 'Interactive', in the sense that all files whose name contains the string Interactive have to be translated to ipynb format with option run set to false.

    Example: 'runExcluded','UserInteraction'

    Data Types: logical

    Output Arguments

    expand all

    Incl —structured information of translated files Cell. Cell of size r-times-4 containing detailed information about the files present in required folder or subfolders for which jpynb format has been created

    The columns of Incl contain the following information: Incl(:,1)= name of the m file (with extension);

    Incl(:,2:3)= Information which has been added in the second column of the table inside README.md out(:,4)= file paths;

    Excluded —structured information of m files not included. Cell

    Cell of size r-times-5 containing detailed information about the files present in required folder or folders if dirpath is a cell array of strings but which have been excluded by the filters.

    The columns of Excluded contain the following information: Excluded(:,1)= name of the file (with extension);

    Excluded(:,2)= date (in local format);

    Excluded(:,3)= size of the files in bytes;

    Excluded(:,4)= boolean 1 if name is a folder and 0 if name is a file;

    Excluded(:,5)= Modification date as serial date number;

    References

    This page has been automatically generated by our routine publishFS