Getting average of a single row of data
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
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)
?
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
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
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!