calculating maximum acceleration that occured 3 time
Show older comments
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 Comments
Walter Roberson
on 11 May 2021
If you findpeaks() and then sort values at the peaks in descending order, then the third value is the maximum that occurs at least 3 times.
Jan
on 11 May 2021
The question is still not clear. In your diagram there are no 3 equal peaks. The expression "intersection" sounds confusing also.
Are you looking for the 3 highest peaks in your data? Then Walter's suggestion is a clean solution.
Avoid dummy code, which does not do anything, like:
size(acc);
size(T);
[] is the Matlab operator for a concatenation. In the line:
acceleration = [acc];
you concatenate acc with nothing, so the [] operation is a waste of time only.
Walter Roberson
on 11 May 2021
Suppose your data had 6 peak accelerations. Three of the peak values were exactly the same, bit for bit, 0.5 -- so the exact same acceleration occurred 3 times. The other 3 peak values were 0.7, 0.8, 0.9 -- three unequal values that are individually larger than the 0.5 values.
Are you saying that the result you would want would be the exactly repeated 0.5 values, the maximum acceleration that "occurred three times" ? Or would you want the 0.7, 0.8, 0.9 values, under the continuity assumption that to reach 0.8 and 0.9 that the accleration must surely have gone "through" 0.7 and so even though we did not happen to take readings at those exact times, we can infer that 0.7 happened three times ?
farid pr
on 11 May 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
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))
Accepted Answer
More Answers (0)
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
