MATLAB: How to post process each variable in a mat file

all variablesall vectorsMATLABprocessreassign variables name

I am trying to downsample all the variables in a mat file.
I can use downsample(var, newSampling) to downsample an individual variables but what to do if i need to downsample all the vectors in the mat file.
load ('my_mat_file_here.mat')
list_var = who; % to get the list of variables
for kk = 1:1:length(list_var) % to run the loop
% downsample(eval(list_var{kk}),10); <– this part is working as expected with eval
[list_var{kk} '_1hz'] = downsample(eval(list_var{kk}),10);
end
% in this part how to define a new variable
% i am trying to use the variable name from list_var which is a character
% and add _1hs to ths string but matlab won't allow it to % be used as a varaible name
% trying to avoid using assignin & eval to assign the new variable to my base workspce
% any help appreciated.

Best Answer

S = load(filename)
fn = fieldnames(S)
Fc = length(fn)
for k = 1 : Fc
F = fn{k}
Data = S.(F)
Process Data
end