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

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???

 채택된 답변

You have two columns, so
squeeze( sum( reshape(YourData, 40, [], 2) ) )

댓글 수: 7

clc;
clear all;
close all;
fid = fopen('file name.txt');
datacell = textscan(fid,'%f%f%f%*[^\n]',...
'delimiter','\t');
fclose(fid);
A = datacell{2};
B=datacell{3};
C=A-B;
sir... with this code i can read the datas from a text file.... reshape is not working to sum up the 1st 40 datapoints.... based upon this code what changes i have to make??
error in squeeze( sum( reshape(YourData, 40, [], 2) ) )... i can't clear the error...
The YourData that I used should be two column, as my assumption was that you wanted to do this addition as one step rather than one column at a time.
Sir , this is the error shown.... pls give a suggetion
Error using reshape Product of known dimensions, 80, not divisible into total number of elements, 3.
This works just fine for me:
YourData = rand(14000, 2); % Create random sample data 14,000 rows, 2 cols
squeeze( sum( reshape(YourData, 40, [], 2) ) )
What does it say when you do
whos YourData
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.
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개)

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)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2014년 2월 13일

편집:

2014년 2월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by