how can i add 1-40,41-80, 81-120 and so on till 14000 datapoints which is in a text file?

2 次查看(过去 30 天)
sir....i have a text file which consist of 14000 rows and 2 columns.... i have to add the 40 points each till 14000 data... means 1-40 , 41-80, 81-120 and so on... what should i do for that???

采纳的回答

Walter Roberson
Walter Roberson 2014-2-13
You have two columns, so
squeeze( sum( reshape(YourData, 40, [], 2) ) )
  7 个评论
Ruby
Ruby 2014-2-15
编辑:Walter Roberson 2014-2-15
clc;
clear all;
close all;
fid = fopen('filename.txt');
datacell= textscan(fid,'%f%f%f%*[^\n]',...
'delimiter','\t');
fclose(fid);
A = datacell{2};
B=datacell{3};
C=A-B;
datacell=rand(14000,2);
squeeze( sum( reshape(datacell, 40, [], 2) ) );
by using this error comes like..
Error using reshape
Product of known dimensions, 80, not divisible into total number of elements, 3.
Ruby
Ruby 2014-2-15
编辑:Walter Roberson 2014-2-15
fid = fopen('filename.txt');
datacell= textscan(fid,'%f%f%f%*[^\n]',...
'delimiter','\t');
fclose(fid);
A = datacell{2};
B=datacell{3};
C=A-B;
t=0.0005:0.0005:0.065;
A1= squeeze( sum( reshape(A, 40, [], 1) ) );
B1=squeeze( sum( reshape(B, 40, [], 1) ) );
C1=A1-B1;
subplot(3,1,1);
stem(C1);
b=[0.69977431651797461 -0.1814575955924495 1.4113120181091672 -0.18145759559244945 0.69977431651797473];
a=[1 -0.21440197757618362 1.3190484139225416 -0.148513213608716 0.491812237222576];
y =filter(b,a,C1);
subplot(3,1,2);
stem(y);
d=[0.0000089848614639706426 0.0000035939445855882617 0.0000053909168783823964 0.0000035939445855882685 0.00000089848614639706807]
e=[1 -3.8358255406473472 5.5208191366222277 -3.5335352194630145 0.8485559996647685]
z=filter(d,e,C1);
subplot(3,1,3);
stem(z);
code is working... im using two filters here... notch and low pass filter..i have to find the statistics of the plot.... standard deviation and mean... what i should do???

请先登录,再进行评论。

更多回答(1 个)

Jos (10584)
Jos (10584) 2014-2-13
In cases when the total number of elements is not divisible by the size of the smaller groups, and reshape cannot be used, this trick with accumarray may be useful:
V = 1:10 ;
n = 3 ;
rem(numel(V),n) % :-(
ix = floor((0:numel(V)-1)/3) ;
R = accumarray(ix, V ,@sum)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by