Define a common relative search path for custom Mupad procedures

Imagine that I have mupad-notebook myMupadNotebook.mn in the path 'C:\projectFolder\ABC\abc\' . It calls the procedure MyMupadProcedure.mu , which is located in 'C:\DEF\GHI\' .

Now I have a Matlab script main.m in 'C:\projectFolder\XYZ\xyz\' with the contents:

 nb = mupad('C:\projectFolder\ABC\abc\myMupadNotebook.mn'); status = evaluateMuPADNotebook(nb); 

Thus, it initializes the symbolic engine and executes the Mupad script. But the Mupad script requires knowing where to find the procedure. Therefore, I can define some launch commands (or run script) in a Mupad laptop using File-> Properties-> Run Commands as follows:

 READPATH := "C:\DEF\GHI\"; read("MyMupadProcedure.mu"); 

But now I work on different machines, and the absolute paths to the folders are different, but the relative paths are the same. How can I use my scripts on all machines?

In Matlab, I just installed SearchPath on every computer and it works, is there anything equivalent for Mupad?


As an alternative, this will already help if I can transfer the line from Matlab to Mupad, and I just write the start commands in the header of my laptop and determine the relative path with the Matlab functions. But all combinations of the following lines just don't work:

 syms X X = 'hello' setVar(nb,'X',X) evalin(nb,['X := "' X '"']) 
+3
source share
1 answer

You might think that integrating MuPad into Matlab is much better.

Direct transfer from variables and strings from Matlab to MuPad, in addition to symbolic expressions ( setVar ), seems impossible. Correct me if I am wrong. However, you can write files in Matlab with a relative path and read files in MuPad with a relative path.

Thus, you can write the path where the MuPad procedures are stored to a text file located in the same folder as the MuPad notebook:

 %// determined with pwd, cd and string manipulation etc MuPadNotebookPath = 'C:\projectFolder\ABC\abc\' MuPadProceduresPath = 'C:\DEF\GHI\'; fid = fopen( [MuPadNotebookPath '\parameters.txt'], 'w'); fprintf(fid,'%s\r\n%', strrep(MuPadProceduresPath ,'\','\\')); %' fclose(fid); 

Now in 'C:\projectFolder\ABC\abc\' will be a parameters.txt file.

In MuPad, you can use the NOTEBOOKPATH environment variable to get both the parameters.txt directory and myMupadNotebook.mn directory .

ftextinput can then be used to read into the path 'C:\DEF\GHI\' from a text file. Finally, you can install READPATH .

 cfgfile := NOTEBOOKPATH . "parameters.txt": rpath = ftextinput(cfgfile, rpath): READPATH := rpath: read("MyMupadProcedure.mu"); 

In general, it looks like this:

 nb = mupad(MuPadNotebookPath); fid = fopen( [MuPadNotebookPath '\parameters.txt'], 'w'); fprintf(fid,'%s\r\n%', strrep(MuPadProceduresPath ,'\','\\')); %' fclose(fid); status = evaluateMuPADNotebook(nb); 
+3
source

All Articles