필터 지우기
필터 지우기

How to average values in a structure

조회 수: 16 (최근 30일)
Anantha Padmanabhan
Anantha Padmanabhan 2016년 8월 24일
답변: Andrei Bobrov 2016년 8월 24일
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.
  댓글 수: 2
Andrei Bobrov
Andrei Bobrov 2016년 8월 24일
Please attach your data
Anantha Padmanabhan
Anantha Padmanabhan 2016년 8월 24일
So as you see I have a structure with 3 fields. Each value represents the velocity at every 0.05 seconds so in total for a time of 960/20=48 seconds. I want have second averaged values, So I would like to average every 20 values each of them which are 25*25.
So at the end I would like to have an output structure which has 48 lines and each dataset has 25*25 values.

댓글을 달려면 로그인하십시오.

채택된 답변

Thorsten
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
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));

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by