Hello Konstantinos,
There kind of is, but Cedric is absolutely right. I have very rarely seen variable names as strings to be necessary in a workflow. However, if you'd like to do it, you can define your own function that then calls inputname: function varNames = getVarNames(varargin)
varNames = cell(1,nargin);
for k = 1:nargin
varNames{k} = inputname(k);
end
end
This issue with this is the way that you are looking to call it. You say that you first create your cell array:
VarCell = {P_scav, T_exh, P_eng ...
At this point, VarCell does not contain any information about which variables were used to create it. It only knows what the data in those variables was, since it now contains a copy of that data. You'll need to call this getVarNames function with each of those input arguments.
VarCellChar = getVarNames(P_scav, T_exh, P_eng ...
at which point you might as well just create the cell array manually. What you could do is make this function output both VarCell and VarCellChar, and just use it as a packaging and naming function though:
function [varCell, varNames] = getVarCellAndNames(varargin)
varCell = varargin;
varNames = cell(1,nargin);
for k = 1:nargin
varNames{k} = inputname(k);
end
end
It'll need to be your own function, since inputname only works on function inputs. And it requires the loop, since inputname only takes scalars.
But definitely think hard about if there is another better way to go about getting the result you want.
-Cam
Best Answer