Average of several (different, across) structures
24 ビュー (過去 30 日間)
古いコメントを表示
I have 10 structures with 6 fields, each with 3D arrays. All of them have the same organization.
I want to do the average of the 10 structures, as a result I would have 1 mean structure with 6 fields, each with 3D arrays.
For example, I have:
Subject_1_RMSE_angle =
struct with fields:
narxwalk: [17×10×16 double]
EMGwalk: [17×10×16 double]
narxup: [17×10×16 double]
EMGup: [17×10×16 double]
narxdown: [17×10×16 double]
EMGdown: [17×10×16 double]
Subject_2_RMSE_angle =
struct with fields:
narxwalk: [17×10×16 double]
EMGwalk: [17×10×16 double]
narxup: [17×10×16 double]
EMGup: [17×10×16 double]
narxdown: [17×10×16 double]
EMGdown: [17×10×16 double]
Subject_3_RMSE_angle =
struct with fields:
narxwalk: [17×10×16 double]
EMGwalk: [17×10×16 double]
narxup: [17×10×16 double]
EMGup: [17×10×16 double]
narxdown: [17×10×16 double]
EMGdown: [17×10×16 double]
then do the mean, and have a results as:
Subject_MEANs_RMSE_angle =
struct with fields:
narxwalk: [17×10×16 double]
EMGwalk: [17×10×16 double]
narxup: [17×10×16 double]
EMGup: [17×10×16 double]
narxdown: [17×10×16 double]
EMGdown: [17×10×16 double]
Thank you.
1 件のコメント
MARCO BERGONZI
2020 年 9 月 10 日
function [outmode,outmean,outmedian,outprcile]=mfromstruct(nomestruttura,nomecampo,percentile_voluto)
pos=length(nomestruttura);
x=zeros(pos,1);
t=numel(nomestruttura(1).(nomecampo));
outmode=nomestruttura(1).(nomecampo)*0;
outmean=outmode;
outmedian=outmode;
outprcile=outmode;
for j=1:t
for i=1:pos
x(i)=nomestruttura(i).(nomecampo)(j);
end
outmode(j)=mode(x);
outmean(j)=mean(x);
outmedian(j)=median(x);
outprcile(j)=prctile(x,percentile_voluto);
end
end
採用された回答
Stephen23
2019 年 4 月 18 日
編集済み: Stephen23
2019 年 4 月 18 日
Fake data in scalar structures:
S1 = struct('A',randi(99,4,3,2),'B',randi(99,4,3,2));
S2 = struct('A',randi(99,4,3,2),'B',randi(99,4,3,2));
S3 = struct('A',randi(99,4,3,2),'B',randi(99,4,3,2));
SX = [S1,S2,S3];
Concatenate data from each field, calculate mean:
C = fieldnames(SX);
SZ = struct(); % scalar structure
for k = 1:numel(C)
F = C{k};
SZ.(F) = mean(cat(4,SX.(F)),4);
end
SZ is a scalar output structure containing the means of the input scalar structures.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!