Getting average of a single row of data
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposte (3)
the cyclist
il 6 Ago 2013
Are you sure that Seg1.P_wave is at least 747 elements long?
What is the result of doing
size(Seg1.P_wave)
?
Azzi Abdelmalek
il 6 Ago 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 Commento
Azzi Abdelmalek
il 6 Ago 2013
There is a difference between
b.m=1:5
%and
c=struct('m',num2cell(1:5))
% numel(b)=1
% numel(c)=5
David Sanchez
il 6 Ago 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.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!