peak additions /array addition
조회 수: 1 (최근 30일)
이전 댓글 표시
I have some code calculating each individual peaks, how can i store them into a large array according to X axis and add them up if they are overlapped.so i should get something like the plot ,
![](https://www.mathworks.com/matlabcentral/images/broken_image.png)
For small range of vt, it will work when I use vt = 5323:stp:5330;
but it wont work if the range is big, say vt=5000:6000. Thanks,
My code:
DT = [1 1 5323.951020 9.682E-22 1.867E+00 .09040 .454
1 1 5327.295500 4.680E-23 2.287E+00 .07510 .301
1 1 5327.390350 1.819E-20 9.299E+00 .10290 .443
1 1 5327.648670 5.002E-23 7.875E-02 .09590 .439
1 1 5327.678120 8.068E-23 5.441E-02 .09320 .429
1 2 5327.964260 1.694E-23 3.105E+00 .09720 .474
1 1 5328.113150 5.769E-23 5.578E-02 .08630 .420
1 1 5329.995810 4.922E-22 1.668E-01 .07400 .460
1 1 5330.470210 3.135E-23 3.254E-02 .09880 .510]; % test data
T = 266;
P = 0.95;
stp = P/100;
a = 1/2.5;
Vgt = 0;
gD(k) = 1.23E-4*sqrt(T/22);
gL(k) = 0.1*P;
for k =1:1:length(DT(:,1))
% % %%% calcualte each peak with 401 pts
vt = DT(k,3)-200*stp:stp:DT(k,3)+ 200*stp;
x=3*(vt-DT(k,3))/gD(k);
y =3*gL(k)/gD(k);
sigma1=0;
sigma2=0;
sigma3=0;
for n = 1:1:20000
sigma1 = sigma1 + 1/(a^2*n^2 + y^2).* exp(-(a^2*n^2 + x.^2));
sigma2 = sigma2 + 1/(a^2*n^2 + y^2).* exp(-(a*n + x).^2);
sigma3 = sigma3 + 1/(a^2*n^2 + y^2).* exp(-(a*n - x).^2);
end
Vgt = exp(-x.^2).*erfcx(y).*cos(2*x.*y)+...
2*a*x.*sin(x.*y)/pi.*exp(-x.^2).*sin(x*y)/(x*y)+...
2*a/pi.*(-y.*cos(2*x.*y).*sigma1 + y/2.*sigma2 +y/2.*sigma3);
hold on;
plot(vt,Vgt,'.-b')
end
채택된 답변
Image Analyst
2013년 9월 8일
We don't understand what you're asking. To add arrays, just use the "+" operation:
sumArray = array1 + array2 + array3;
댓글 수: 2
Image Analyst
2013년 9월 8일
I didn't run your code. If your peaks show up at different indexes, then you're going to have to make a "canvass" long enough to fit them all (basically three times the length of the single array), then place the array so that the peak occurs at the desired index. For example, let's say that your signals are 100 long and your peak could occur anywhere within that 100 elements. So you make a canvass 300 long. This could take a signal that had a peak at the last element (by placing it at element 101 of the canvass), or take a signal that had a peak at element 1 (by placing it at element 200). But you specify where you want all the peaks to be centered. So let's say you want the peaks to be in the middle, at index 150. Now let's say your signal had a peak at element 60, so you need that 60 to happen at 150 of the canvass. So you need to add (150-60) to every element.
theShift = 150-60;
canvass(theShift:theShift+99) = canvass(theShift:theShift+99) + yourSignal;
추가 답변 (1개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!