Include a second file in a script using logical indexing

1 次查看(过去 30 天)
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

回答(1 个)

Areej Varamban Kallan
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 个评论
Steven Lord
Steven Lord 2018-12-3
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by