MATLAB: How to Create a loop that can find the Max Values of different matrices

create a loop for finding max valuescreating an array of max values from different matricesmax values of different maticesusing a loop to create an array of max values

I'm new to MatLab and I want to create an array that contains all the max values of different matrices from my workspace using a while Loop (or any loop).

Best Answer

save copy_of_all_variables.mat
copy_of_all_variables = load('copy_of_all_variables.mat');
delete('copy_of_all_variables.mat');
varnames = fieldnames(copy_of_all_variables);
numvars = length(varnames);
max_values = cell(numvars,1);
for K = 1 : numvars
thisvarname = varnames{K};
thisvarvalue = copy_of_all_variables.(thisvarname);
if isnumeric(thisvarvalue) || islogical(thisvarvalue) || ischar(thisvarvalue) || ismethod(thisvarvalue, 'max')
max_values{K} = max(thisvarvalue);
end
end
Now max_values is a cell array that contains the maximums of every variable for which "max" makes sense to apply. The corresponding variable names are in varnames.