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 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