Davin - have you tried stepping through the code to see what is happening? Let's suppose that you have a function called myFunc, and you have the five (fints) tables in the workspace. In the Command Window you type
Now suppose the definition for this function uses your second code example
function myFunc
Global = []
a = who
for i = 1:length(a)
Data = evalin('base', [a{i}.Close])
Global = [Global; Data(:,2)]
end
The first line of code declares an empty array named Global. This should be renamed so as not to be confused with the built-in MATLAB global "qualifier" for global variables. Perhaps name it given the data that is being used to populate it: allCloseData. The next line calls the who function which, since we are evaluating it from a function, will return only those variables that have been declared in this function. I think that you want to grab the variables in the base workspace. So try
allBaseVars = evalin('base','who');
Now, you iterate over each one and grab the last (close) column. You mentioned that you are concerned with accessing variables that aren't of type fints - so just add a check on the class type
for k=1:length(allBaseVars)
classType = evalin('base',['class(' allBaseVars{k} ')']);
if strcmpi(classType,'fints')
end
end
I don't have the Financial Toolbox so I'm guessing that the class type of a Financial Time Series object is fints. You can verify this easily enough by just type class(myFintsTable) in the Command Window and seeing what is returned.
Now we can "do stuff" if the object is of type fints. The code will be similar to what you have shown, but the expression (the second input to evalin) must be a string and not the statement hat you have shown
data = evalin('base',[allBaseVars{k} '.Close']);
allCloseData = [allCloseData ; data];
So your function now becomes
function myFunc
allCloseData = [];
allBaseVars = evalin('base','who');
for k=1:length(allBaseVars)
classType = evalin('base',['class(' allBaseVars{k} ')']);
if strcmpi(classType,'fints')
data = evalin('base',[allBaseVars{k} '.Close']);
allCloseData = [allCloseData ; data];
end
end
If you want to assign the allCloseData to the base workspace, then just add the following line of code to your function
assignin('base', 'allCloseData', allCloseData);