calculating maximum acceleration that occured 3 time

8 Ansichten (letzte 30 Tage)
farid pr
farid pr am 11 Mai 2021
Kommentiert: Walter Roberson am 16 Mai 2021
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 Kommentare
Adam Danz
Adam Danz am 11 Mai 2021
Bearbeitet: Adam Danz am 11 Mai 2021
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
Adam Danz am 12 Mai 2021
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))

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

farid pr
farid pr am 16 Mai 2021
Hello again, Many thanks for your attention
I found a definition for my purpose(From Nuttli 1997) :
this parameter gives the sustained maximum acceleration/velocity during three cycles,and is defined as the third highest absolute value of acceleration/velocity in the time-history (note: in order for an absolute value to be considered as a "maximum",it must be larger than values 20 steps before and 20 steps after).
  1 Kommentar
Walter Roberson
Walter Roberson am 16 Mai 2021
... So that would be findpeaks() with a 'MinPeakDistance' option, and then sorting based upon absolute value and taking the third highest.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by