How to average values in a structure
5 次查看(过去 30 天)
显示 更早的评论
Hello! i have a 1*60 structure which represents minute data and each field is a 25*25 double. Is there a matlab command to average every 10 values in the structure so that I can arrive at 10 second averaged data fields. My output should be a structure of size 1*10 with each value being of size 25*25 double. I was hoping there was an easier way of doing this instead of playing around with loops.
采纳的回答
Thorsten
2016-8-24
j = 1;
for i= 1:10:60
snew(j).field = mean(cat(3, s(i:i+9).field), 3);
j = j + 1;
end
更多回答(1 个)
Andrei Bobrov
2016-8-24
for your data (struct 1 x 960)
x = 20;
Q = struct2cell(data);
m = size(Q);
n = size(Q{1});
y = m(end)/x;
a = reshape(cat(3,Q{:}),[n, m(1),x,y]);
b = mean(a,4);
c = reshape(num2cell(b,[1 2]),m(1),y);
out = cell2struct(c,fieldnames(data));
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!