calculating maximum acceleration that occured 3 time
6 次查看(过去 30 天)
显示 更早的评论
I need to find maximum acceleration that occured 3 times.I know that i need to use a loop for this problem like this :
false example code :
clc
clear all
A = [ 1 2 3 1 1 6 3 4 2 2 1 1 1 ];
N = 1
while N <= 3
N = numel(max(A)) + 1;
find(hist(A,unique(A))= 3)
r = A;
disp(max(r));
for N = 3
disp(A)
end
end
cycle = A
this is my code :
clc
clear
close all
%Read acceleration txt file%
acc = textread('Ax.txt'); %g
size(acc);
PGA = max(abs(acc)) %g
T = (0:0.01:53.71);
size(T);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
acceleration = [acc]; %g
dt = 0.01; % change in time (seconds)
dtVel = acceleration * dt * 981; %(cm/s) = (acc * g * 100) * (s)
vel = cumtrapz([dtVel]); %cm/s
PGV = max(abs(vel)) %cm/s
timev = dt * (0:length(acceleration)-1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
velocity = [vel]; %cm/s
dt = 0.01; % change in time (seconds)
dtDis = velocity * dt;
dis = cumtrapz([dtDis]); %cm
PGD = max(abs(dis)) %cm
timed = dt * (0:length(velocity)-1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Plot%
x = T;
% 1st subplot
ax1 = subplot(3,1,1);
y1 = acc;
plot(ax1,x,y1)
grid on
ylabel(ax1,'Acceleration(g)')
xlabel('time(s)')
% 2nd subplot
ax2 = subplot(3,1,2);
y2 = vel;
plot(ax2,x,y2)
grid on
ylabel(ax2,'Velocity(cm/s)')
xlabel('time(s)')
%3rd subplot%
ax3 = subplot(3,1,3);
y3 = dis;
plot(ax3,x,y3)
grid on
ylabel(ax3,'Displacement(cm)')
xlabel('time(s)')
7 个评论
Adam Danz
2021-5-11
编辑:Adam Danz
2021-5-11
I'm confused by the disconnect between the image and what you're describing, "I need to find a max acceleration that occures 3 times(one acceleration at 3 points on time-line)." I think the word "max" is throwing me off. If the y-axis is acceleration, the red dots show the first n coordinates that intersect with a y-value. Those coordinates are not the max acceleration except for the one on the purple line.
If the y-axis in your image is "Max acceleration" where all points are a maximum acceleration of something, then the description matches the image a bit better, though still cryptic.
"If I had only one hour to save the world, I would spend fifty-five minutes defining the problem, and only five minutes finding the solution." -Albert Einstein
Adam Danz
2021-5-12
Moving my answer here because it no longer seems to apply to the evolving question.
Use findpeaks along with maxk to locate the 3 tallest peaks.
acc = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/614985/Ax.txt');
[yPeak, xPeak] = findpeaks(acc);
[maxPeaks, maxPkIdx] = maxk(yPeak, 3);
figure()
plot(acc)
hold on
plot(xPeak(maxPkIdx), maxPeaks, 'ro')
xlim([0 1500]) % zoom into relevant section
% Draw threshold line at the shortest of the 3 peaks.
shortestMax = min(maxPeaks);
yline(shortestMax, 'm-', sprintf('%.4f',shortestMax))
采纳的回答
farid pr
2021-5-16
1 个评论
Walter Roberson
2021-5-16
... So that would be findpeaks() with a 'MinPeakDistance' option, and then sorting based upon absolute value and taking the third highest.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!