フィルターのクリア

Include a second file in a script using logical indexing

1 回表示 (過去 30 日間)
Ross Hanna
Ross Hanna 2018 年 11 月 22 日
コメント済み: Steven Lord 2018 年 12 月 3 日
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
Areej Varamban Kallan 2018 年 12 月 3 日
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 Center および File ExchangeEntering Commands についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by