Hello Sandeep,
It's not clear what you mean by "statistics", nor what you know about each field of the struct. However, if I were to assume you had something like this:
S = struct('A', rand(3), 'X', rand(4));
so all data in every field in the structure is numeric, and I wanted to compute the size of each matrix, I could do something like:
sizeStruct = struct;
fields = fieldnames(S);
for k = 1:numel(fields)
f = fields{k};
sizeStruct.(f) = size(S.(f));
end
If you want to avoid a for loop, you can get fancy with cellfun: S = struct('A', rand(3), 'X', rand(4));
fields = fieldnames(S);
sizeCell = cellfun(@(f) size(S.(f)), fields, 'UniformOutput', false);
Now you have all the data in a cell array, in the same order as the fields cell array. If you want it back into a struct with the same fields as S, you could do the same thing with cellfun, or get fancy with indexing:
C = [fields.' ; sizeCell.'];
sizeStruct = struct(C{:});
Is this the kind of thing you're looking for? If not, what "statistics" do you mean, and what kind of data is contained within the struct?
-Cam
Best Answer