- in your func.m add a comment with a special TAG (e.g. %#mycode), then replace the TAG with the code you want. This can be done with simple fileread(filename). This will work for *.m or any other text files
- in your func.m call a script as per is suggesting (this could be empty or with data) so your func.m will always run, it may error out if the script file is not generated properly
- in your func.m if you are only loading variables you could always load a mat file
How to insert code segments from another MATLAB file?
37 views (last 30 days)
Could anyone tell me how can I "import" MATLAB code segments into another code?
I mean, I have some parameters in a file and I want to embed it in a function, for example, a data input.
y=2; % or something more complex than that
function result = func(M)
% I want to insert my input here
result = M+y;
Thanks for your help!
GT on 18 Dec 2018
There usually are 3 ways that I have seen people do this.
Hope this helps