Getting average of a single row of data

2 visualizaciones (últimos 30 días)
David
David el 6 de Ag. de 2013
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.

Respuestas (3)

the cyclist
the cyclist el 6 de Ag. de 2013
Are you sure that Seg1.P_wave is at least 747 elements long?
What is the result of doing
size(Seg1.P_wave)
?
  1 comentario
David
David el 6 de Ag. de 2013
Thanks for the response,
Yes that variable is 747 elements long, when I run size(Seg1.P_wave) the resulting output is: 1 747.

Iniciar sesión para comentar.


Azzi Abdelmalek
Azzi Abdelmalek el 6 de Ag. de 2013
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 comentario
Azzi Abdelmalek
Azzi Abdelmalek el 6 de Ag. de 2013
There is a difference between
b.m=1:5
%and
c=struct('m',num2cell(1:5))
% numel(b)=1
% numel(c)=5

Iniciar sesión para comentar.


David Sanchez
David Sanchez el 6 de Ag. de 2013
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 comentario
David
David el 6 de Ag. de 2013
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.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by