MATLAB: How to get the order indices in a character array

MATLAB

Here is my cell Array, consider it as an input:
ans =
7×1 cell array
{'x_air' }
{'v_air' }
{'p_headspace' }
{'p_environment' }
{'x_air_standard' }
{'N_StirrerSpeed [s^-1]'}
{'v_air;Sparger' }
And I have this character Array (consider as output):
ans =
'v_air,p_headspace,p_environment,x_air,x_air_standard,N_StirrerSpeed [s^-1],v_air;Sparger'
Wanted result:
indices = [2;3;4;1;5;6;7];
The idea is to know which Output is connected to which Input. How to do that?
Once the indices have been recorded, the Input Array will be renamed, but Connection are not changed. For ex.: if i rename 'x_air' at Input then i want to know that it goes to 4th Output.

Best Answer

c = {...
'x_air'
'v_air'
'p_headspace'
'p_environment'
'x_air_standard'
'N_StirrerSpeed [s^-1]'
'v_air;Sparger'};
str = 'v_air,p_headspace,p_environment,x_air,x_air_standard,N_StirrerSpeed [s^-1],v_air;Sparger';
[~,loc] = ismember(regexp(str,',','split'), c);
Results:
loc =
2 3 4 1 5 6 7
As Ben indicates in his comment above, this will only work if none of your target strings include commas. If they do, a little extra parsing will be needed.
Related Question