From d1d2496c8e280c294ae80147eef496d7c74f6ca0 Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Sun, 1 Aug 2004 16:43:14 +0000 Subject: [PATCH] added support for cell arrays of element names --- .../cantera/@ThermoPhase/elementIndex.m | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Cantera/matlab/cantera/@ThermoPhase/elementIndex.m b/Cantera/matlab/cantera/@ThermoPhase/elementIndex.m index 943ed078a..0d8ff1d24 100644 --- a/Cantera/matlab/cantera/@ThermoPhase/elementIndex.m +++ b/Cantera/matlab/cantera/@ThermoPhase/elementIndex.m @@ -1,10 +1,15 @@ -function n = elementIndex(a,name) +function k = elementIndex(a,name) % ELEMENTINDEX - The element index of the element with name % 'name'. % % The index is an integer assigned to each element in sequence as it % is read in from the input file. % +% If name is a single string, the return value will be a integer +% containing the corresponding index. If it is an cell array of +% strings, the output will be an array of the same shape +% containing the indices. +% % NOTE: In keeping with the conventions used by Matlab, this method % returns 1 for the first element. In contrast, the corresponding % method elementIndex in the Cantera C++ and Python interfaces @@ -13,4 +18,15 @@ function n = elementIndex(a,name) % ic = elementIndex(gas, 'C'); % ih = elementIndex(gas, 'H'); % - n = phase_get(a.tp_id,13,name); \ No newline at end of file + +if iscell(name) + [m, n] = size(name); + k = zeros(m,n); + for i = 1:m + for j = 1:n + k(i,j) = phase_get(a.tp_id,13,name{i,j}); + end + end +else + k = phase_get(a.tp_id,13,name); +end