Averaging mutiple structures to get a single mean waveform

1 vue (au cours des 30 derniers jours)
Jake Bowd
Jake Bowd le 24 Avr 2020
Hi,
I have a structure called Results.
Within this structure I have x amount of fields. Each field having a 1xn structure. I would then like to make an average waveform from the 1xn structure for each field.
Conceptually, this is a very basic thing to do, but struggling to apply it.
Many thanks,

Réponse acceptée

Srivardhan Gadila
Srivardhan Gadila le 1 Mai 2020
The following code might help you:
clear all
a(1).waveforms = rand(101,1);
a(2).waveforms = rand(101,1);
a(3).waveforms = rand(101,1);
Results.a = a;
Results.b = a;
Results.c = a;
fieldNames = fieldnames(Results);
for i = 1:numel(fieldNames)
res = arrayfun(@(x)x.waveforms,Results.(fieldNames{i}),'UniformOutput',false);
resMat = cell2mat(res);
avgWaveforms.(fieldNames{i}) = mean(resMat,2);
end
avgWaveforms
Refer to arrayfun & mean for more information and related examples.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by