Subsystem reference won't load properly into Simulink model

33 visualizzazioni (ultimi 30 giorni)
Hello,
I have project with the following structure:
  • a folder containing a Simulink file "A",
  • a folder containing a subfolder which hosts a masked subsystem file "B".
Simulink file "A" contains a subsytem reference to "B"; "B" has a model mask containing several non-tunable parameters. "A" has an init function which is automatically invoked before the start of every simulation, which is supposed to assign values to the parameters contained within "B" 's mask.
Everything works as it should if I open "B", then "A", then launch a simulation in "A". However if, instead, I select both folders and click "Add to Path -> Selected Folders and Subfolders", then open only "A", the subsystem doesn't seem to load properly. In particular, it seems to load without its mask. A warning also appears in the simulink diagnostics screen saying that the subsystem reference couldn't be updated because there are not enough input arguments, which I have no clue what it could possibly mean in this case.
All sorts of strange errors also tend to appear in the command window, sometimes saying that some Stateflow block couldn't be copied to the clipboard because it was corrupted. I'm not using Stateflow in this project at all, so again, no clue.
I hope this was clear enough, unfortunately I am pretty new to both subsystem references and subsystem masks in general, and I haven't been able to find anyone with a similar issue.
  3 Commenti
Giovanni Gasperini
Giovanni Gasperini il 22 Mar 2023
Sure, the init function is a call to an .m file which simply does the following:
clear all
clc
mfilename = 'Init_batt_pack.m';
folder = fileparts(which(mfilename));
addpath([folder '\Components']);
% add here battery pack topology
Ns = [3 3];
Np = length(Ns);
N_cells = sum(Ns);
load("theta.mat"); % param matrix
n_state = 2; % 1 + RC_pairs
init_cond = [0.8 0.75 0.85 0.8 0.6 0.75; % SOC
zeros(n_state-1, N_cells)]; % Vrc
Subsystem "B" is a model of a battery pack which acceps Ns, Np, N_cells, theta, n_state and init_cond as mask parameters. The path it resides in is the current folder + '/Components', as you can see in the code.
I've never heard of private or resources folders before. How do I do what you suggest?
Mark McBroom
Mark McBroom il 25 Mar 2023
You could try moving your code from an InitFcn callback to a PreLoadFcn callback. It could be that Simulink is trying to open the SubSystem reference before running the content of the InitFcn.
Other general suggestions on your M code. I would remove the clear all code and I would remove the code for setting path and replace with Simulink Projects for managing maths.
Thanks.
Mark.

Accedi per commentare.

Risposta accettata

Giovanni Gasperini
Giovanni Gasperini il 29 Mar 2023
It turns out that the problem was not in any of the folders mentioned, but in a different folder which I also was including in the path. Apparently my colleague had called one of the files inside of it "error", which is also the name of a MATLAB buit-in function, causing all sorts of strange behaviour when I attempted to include it. Simply changing the file name has fixed the issue.

Più risposte (0)

Categorie

Scopri di più su Interactive Model Editing in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by