Include a second file in a script using logical indexing

1 view (last 30 days)
Hi all
I am creating a script to calculate the NOX output of an IC engine using Pressure Volume data. Unfortunately i cannot show the whole code as it has lots of confidential data from a well known car manufacturer.
In doing so, i have created 3 files, 'Molecular_Analysis_Rich.m', 'Molecular_Analysis_Lean.m' and 'Molecular_Analysis_Stoichiometric.m'. What i am trying to do is call the files into the main script to use the values calculated depending on the value of 'phi'.
I have recently found that logical indexing seems to be much faster than an if statement, so i have been attempting to use that, but i get the follwoing error;
Attempt to execute SCRIPT Molecular_Analysis_Rich as a function:
This is using the following code;
output = cond_rich .* (Molecular_Analysis_Rich)
I believe it is because i have multiple outputs being assigned to a single variable 'output'?
What i am attempting to do is the following but in a more efficient way.
phi = 0.9
cond_rich = phi > 1
cond_stoich = phi == 1
cond_lean = phi < 1
if cond_rich == 1
Molecular_Analysis_Rich
elseif cond_stoich == 1
Molecular_Analysis_Stoichiometric
else cond_lean == 1
Molecular_Analysis_Lean
end
Any help would be appreciated. Thanks

Answers (1)

Areej Varamban Kallan
Areej Varamban Kallan on 3 Dec 2018
Hi Ross,
Please check if the three '.m ' files you mentioned are functions or not. A MATLAB script can call another MATLAB script only if the latter is a function.
  1 Comment
Steven Lord
Steven Lord on 3 Dec 2018
To be a little more precise, script files neither accept input arguments nor return output arguments. That is one of the primary differences between scripts and functions. [The other somewhat related difference is function workspaces.] See this page for more information.
This line of code:
output = cond_rich .* (Molecular_Analysis_Rich)
will work only if Molecular_Analysis_Rich is a variable or if it is a function that returns at least one output argument.

Sign in to comment.

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!