Getting statistics from a struct

I have a struct with experimental data in it. The fields in the struct are input settings and measurement results. For all possible input settings I have a lot of measurement results, but they are not organized.
So for example I have myResults(1).Inputsetting1 and myResults(1).Inputsetting2 as input settings for one experiment and myResults(1).MeasurementA and myResults(1).MeasurementB as measurement results for that experiment. And then there exist e.g. 20 different elements which all share the same input settings. Now I want to know what the mean, standard deviation, etc. is of myResults.MeasurementA and myResults.MeasurementB of all the elements which share the same inputsettings. Is there a simple way to do this?

2 comentarios

dpb
dpb el 29 de Jul. de 2014
Think need some more detail to have specifics, but -- look at
doc structfun
and the section on structures with addressing them, particularly the portion to create hyper-rectangles or arrays of similar data types from various fields. Then you can process those arrays selected by various characteristics.
If you have the Statistics Toolbox, look at
doc struc2dataset
Patrik Ek
Patrik Ek el 30 de Jul. de 2014
Try to parse the struct with functions like fieldnames and so. If you know where to find the data, a recursive parser might do the trick.

Iniciar sesión para comentar.

 Respuesta aceptada

Sara
Sara el 29 de Jul. de 2014
If measurementA is just one value, you can do:
mean([myResults.MeasurementA])
Try it for your data and look at the results and adjust.

7 comentarios

Merijn
Merijn el 30 de Jul. de 2014
If I do this, I get one number as output, which is the mean of all MeasurementA. But that's not what I want. I want to have the mean of all MearusementA which have the same Inputsetting1 and Inputsetting2.
So I'll try to explain with an example. I have a 3 apple trees. Tree 1 had 1 week of sun and 1 week of rain, Tree 2 has 2 weeks of sun and 0 weeks of rain, Tree 3 has 0 weeks of sun and 2 weeks of rain. I pick all the apples of all trees and measure the size and the weight of the apples. Then I write down for each individual apple how many weeks of sun, how many weeks of rain and the size and the weight. These data I have in my struct now, so apple nr.1 has e.g. 1 week of rain and 1 week of sun and weighs 100 grams and is 10 cm in diameter. An like that I have a few thousand apples' statistics in my struct, randomly organized.
Now I want to know the influence of the amount of sun and rain on the size and weight of the apples, so I want to know the mean weight and size of the apples as a function of the rain and sun. Therefore I want to calculate the mean weight and size of all the apples which had the same amount of sun and the same amount of rain. If I do this for all combinations of input variables (sun and rain), I can plot the effect of variables sun and rain on the size and weight of the apples.
So in this example Inputsetting1 and Inputsetting2 are the weeks of sun and rain, and MeasurementA and MeasurementB are the size and weight of the apples.
Does this make my question more clear?
(btw, yes, I have the statistics toolbox)
dpb
dpb el 30 de Jul. de 2014
The question isn't the problem; it's the exact form in which you've stored the data that's not clear (enough) from which to write actual code lines.
Merijn
Merijn el 30 de Jul. de 2014
Merijn
Merijn el 30 de Jul. de 2014
Does that make it clearer?
Sara
Sara el 30 de Jul. de 2014
Ok, now it's clearer. Can you attach your data (or a subset) so we can play with it?
Merijn
Merijn el 30 de Jul. de 2014
Editada: Merijn el 30 de Jul. de 2014
This is a subset of the data. Two input parameters are Droplet_spacing and Gap, and an output is e.g. Area.
Sara
Sara el 30 de Jul. de 2014
Look at the code below. Is that what you are looking for?
clc
clearvars
close all
load('partofresult.mat');
drop_array = [partofresult.Droplet_spacing];
gap_array = [partofresult.Gap];
area_array = [partofresult.Area];
drop = unique([partofresult.Droplet_spacing]);
gap = unique([partofresult.Gap]);
averages = zeros(numel(drop),numel(gap));
for i = 1:numel(drop)
for j = 1:numel(gap)
k = find(drop_array == drop(i) & gap_array == gap(j));
averages(i,j) = mean(area_array(k));
end
end
[drop,gap] = meshgrid(drop,gap);
plot3(drop,gap,averages','o')

Iniciar sesión para comentar.

Más respuestas (1)

Merijn
Merijn el 31 de Jul. de 2014

0 votos

Wow, that's exactly what I need. Thanks a million!

Categorías

Etiquetas

Preguntada:

el 29 de Jul. de 2014

Respondida:

el 31 de Jul. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by