フィルターのクリア

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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by