Getting statistics from a struct

7 ビュー (過去 30 日間)
Merijn
Merijn 2014 年 7 月 29 日
回答済み: Merijn 2014 年 7 月 31 日
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 件のコメント
dpb
dpb 2014 年 7 月 29 日
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 2014 年 7 月 30 日
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.

サインインしてコメントする。

採用された回答

Sara
Sara 2014 年 7 月 29 日
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 件のコメント
Merijn
Merijn 2014 年 7 月 30 日
編集済み: Merijn 2014 年 7 月 30 日
This is a subset of the data. Two input parameters are Droplet_spacing and Gap, and an output is e.g. Area.
Sara
Sara 2014 年 7 月 30 日
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')

サインインしてコメントする。

その他の回答 (1 件)

Merijn
Merijn 2014 年 7 月 31 日
Wow, that's exactly what I need. Thanks a million!

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by