필터 지우기
필터 지우기

Getting average of a single row of data

조회 수: 2 (최근 30일)
David
David 2013년 8월 6일
Hi Everyone,
I have a dataset that contains a single row of data with around 700 columns. This data corresponds to six years. The first year is columns 1:113, second year is columns 114:238, third year is columns 239:362 and so on for the six years. I want to calculate the average for each year individually but am having some difficulties. Here is what I have tried so far:
Seg1.average_power(index)=[mean(Seg1.P_wave(1:113));mean(Seg1.P_wave(114:238));mean(Seg1.P_wave(239:362));mean(Seg1.P_wave(363:491));mean(Seg1.P_wave(492:616));mean(Seg1.P_wave(617:747))];
I have calculated the Seg1.P_wave values already, however when I run the code an error statement is returned stating that the index exceeds the matrix dimensions. There is probably a very simple solution to it but my knowledge and experience of Matlab is very limited. Any help would be greatly appreciated.

답변 (3개)

the cyclist
the cyclist 2013년 8월 6일
Are you sure that Seg1.P_wave is at least 747 elements long?
What is the result of doing
size(Seg1.P_wave)
?
  댓글 수: 1
David
David 2013년 8월 6일
Thanks for the response,
Yes that variable is 747 elements long, when I run size(Seg1.P_wave) the resulting output is: 1 747.

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


Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 6일
Seg1=struct('P_wave',num2cell(rand(1,747))); % Example
a=[Seg1.P_wave]
b={a(1:113);a(114:238);a(239:362);a(363:491);a(492:616);a(617:747)}
out=cellfun(@mean,b)
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 6일
There is a difference between
b.m=1:5
%and
c=struct('m',num2cell(1:5))
% numel(b)=1
% numel(c)=5

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


David Sanchez
David Sanchez 2013년 8월 6일
I think your problem is in:
Seg1.average_power(index)
What's the size of Seg1.average_power?
Make sure you can fit your data into it.
What's that index variable? If you just do ( get rid of index if you can )
Seg1.average_power=[mean(Seg1.P_wave(1:113));...
mean(Seg1.P_wave(114:238));mean(Seg1.P_wave(239:362));...
mean(Seg1.P_wave(363:491));mean(Seg1.P_wave(492:616));...
mean(Seg1.P_wave(617:747))];
you will not have any problem.
  댓글 수: 1
David
David 2013년 8월 6일
Hi David,
You were right, there was no need having index in the code and it seems to work perfectly without it. Thanks for the help, greatly appreciated.

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

카테고리

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