Problem in finding peak, how to find the first peak?
조회 수: 33 (최근 30일)
이전 댓글 표시
Hi, I'm trying to plot the P value (corresponding to a peak in a P-umax plot) in function of "s", a variable linspaced between 0.1 and 2.
the code that produces this plot P-umax for "s=1" is the following:
clc;
clear;
close all;
R=20;
L=3*75;
s=1;
ni=0.3;
E=210000;
w=2;
K=0.5;
%
E1=E/(1-(ni^2));
I=(2*pi*R*(s^3))/12;
k=2*pi*((E*s)/R);
P = linspace(400000,9000000);
y_max_values = zeros(size(P));
for i=1:length(P)
f = @(z,u) [u(2); u(3); u(4); (-1/(E1*I))*((P(i)*u(3))+(k*u(1)))];
bc = @(ua, ub) [ua(1); ua(2)-0.00000001; ub(1); ub(2)+0.00000001];
zmesh = linspace(0, L, 100000);
iguess= @(z) [0; 0; 0; 0];
solinit = bvpinit(zmesh, iguess);
Sol= bvp4c(f, bc, solinit);
x = Sol.x;
y = Sol.y;
idx = (x > 50) & (x < 180);
x_new = x(idx);
y_new = y(1, idx);
y_max_values(i) = max(y_new);
end
figure
hold on
grid on
plot(y_max_values, P)
legend ('cilindro 1 w0')
xlabel ('u_max [mm]')
ylabel ('P [N]')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/373556/image.png)
So I need to find in the plot, the P value corresponding to the first peak of the following P-umax plot, where the umax value moves from zero in the first time. (8x10^5 in this case), and repeat this procedure for every "s".
The P value corresponding to peak I'm trying to find has to be assigned to "Pcr"
I've tried to write something like this but I don't know what to put in the Pcr findpeak function
clc;
clear;
clear;
%------------------------------------------------------------------------
ni=0.3;
L=50;
R=20;
E=210000;
E1=E/(1-ni^2);
%-----------------------------------------------------------------------
s= linspace(0.1,2,10);
I = zeros(size(s));
k = zeros(size(s));
Pcr = zeros(size(s));
%%
P=linspace(7800,3300000,10);
y_max_values= zeros(size(P));
for i=1:length(s)
for j=1:length(P)
f = @(z,u) [u(2); u(3); u(4); (-1/(E1*I(i)))*((P(j)*u(3))+(k(i)*u(1)))];
bc = @(ua, ub) [ua(1); ua(2)-0.00000001; ub(1); ub(2)+0.00000001];
zmesh = linspace(0, L, 100000);
iguess= @(z) [0; 0; 0; 0];
solinit = bvpinit(zmesh, iguess);
Sol= bvp4c(f, bc, solinit);
x = Sol.x;
y = Sol.y;
idx = (x > 50) & (x < 180);
x_new = x(idx);
y_new = y(1, idx);
y_max_values(j) = max(y_new);
Pcr=findpeak (?) %what I should put here?
end
end
%%
figure
hold on
grid on
plot(s, Pcr)
xlabel ('s [mm]')
ylabel ('Pcr [N]')
Could someone help me out ?
Is the the code structure right for the aim I need to?
댓글 수: 11
Star Strider
2020년 10월 8일
The problem is that your code takes forever to run on my desktop machine (relatively new AMD Ryzen 9 3900 12-Core CPU). I simply cannot tie it up for several hours.
Put this line just after the loops (forget about findpeaks for the time being), then run your code and let it finish:
save('federico midei_20201008.mat', 'y_max_values','P','s')
Add or delete from this line whatever variables you want (I included the ones that appear to be most important). Then run your code and attach the federico midei_20201008.mat file to your original post or to a Comment.
We can then explore those results.
답변 (1개)
Star Strider
2020년 10월 12일
I do not see any peaks. It is just sort of L-shaped lines.
That aside, if you do have data with peaks and you only want the first one (with the lowest value of ‘P’), and since your data appears to have no noise:
[pks,locs,wdth,prom] = findpeaks(P, 'NPeaks',1)
will llikely do what you want. It will return only the data for the first peak, which should be the one at about
in the image you posted. (I experimented with this with the sinc function that definitely has peaks.)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/378636/image.png)
To be certain you have the one you want, plot it as:
figure
plot(u_max, P)
hold on
plot(u_max(locs), pks, '+r')
hold off
If you want the one on the top of the plot instead (at about
), try this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/378641/image.png)
[pks,locs,wdth,prom] = findpeaks(P)
figure
plot(u_max, P)
hold on
plot(u_max(locs(end)), pks(end), '+r')
hold off
You can then address them the same way to get their values and locations.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!