How can I access a private folder with a MATLAB Function block in Simulink R2022a?
Show older comments
In the MATLAB editor, I am able to access private folders, which are not on the current path, with scripts and functions in the parent folder. For example, I have a parent folder with files as seen below.

The file 'parentFunction.m' has the following code to call 'matlab.mat', which is stored in the private folder.
function out = parentFunction()
data = load('matlab.mat');
out = data.a;
end
This function is able to successfully load 'matlab.mat' from the private folder. However, when attempting the same implementation in a 'MATLAB Function' block, this is not the case. The model 'parentModel.slx' is constructed as shown.

And the function inside the block is as follows.
function y = fcn()
y = parentFunction();
end
When this model is run, the following error occurs.
Failed to load file 'matlab.mat': 'matlab.mat' is not found in the current folder or on the MATLAB path
I thought that the 'MATLAB Function' block has the same functionality as a script within the MATLAB editor. Is there a workaround that allows the block to access private folders?
Accepted Answer
More Answers (0)
Categories
Find more on Simulink Environment Customization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!