Wrong index acquired or wrong value taken from the index
Show older comments
Hello, I am currently doing some data analysis and need to get certain data points with the use of the "max" and "min" functions. That seems to be fine on its own, however I am going through a for loop and have to gather that single point in each case in the loop and store it in a matrix. That again, works fine. However, half of the numbers acquired seem to be wrong. E.g. I have xmx (x_maximum), from which I acquire the index to find the y value ymn at that point. According to all the graphs in ALL x_maximum cases ymn should be positive. The opposite applied to ymn. However for some reason ymx matrix has some negative values and ymn has some positive values.
I have tested each of those cases individually outside of the for loop and that gives the correct answers (positive for ymx and negative for ymn). So something may be wrong in the code itself, but I can't seem to find it.
If there is anyone who could help I would really appreciate it.
Kind regards, Edvardas
Code given below:
%%Displacement and Velocity Front 1 Hz
load('Front_Damper_1Hz'); %B(n)R(m)_F1Hz (notation)
ymx_big=[];
xmx_big=[];
ymn_big=[];
xmn_big=[];
for n=1:11;
figure(1)
Fbump1=cat(3, -B0R0_F1Hz, -B2R0_F1Hz, -B4R0_F1Hz, -B6R0_F1Hz, -B8R0_F1Hz, -B10R0_F1Hz, -B12R0_F1Hz, -B14R0_F1Hz, -B16R0_F1Hz, -B18R0_F1Hz, -B20R0_F1Hz);
Frebound1= cat(3, -B20R0_F1Hz,-B20R2_F1Hz, -B20R4_F1Hz, -B20R6_F1Hz, -B20R8_F1Hz, -B20R10_F1Hz, -B20R12_F1Hz, -B20R14_F1Hz, -B20R16_F1Hz, -B20R18_F1Hz, -B20R20_F1Hz);
subplot(2,2,1) %bump displacement
hold all
plot(Fbump1(:,2,n), Fbump1(:,1,n)); % displacement
% set(gca,'Ydir','reverse')
% set(gca,'Xdir','reverse')
subplot(2,2,2) %rebound displacement
hold all
plot(Frebound1(:,2,n), Frebound1(:,1,n)); % displacement
% set(gca,'Ydir','reverse')
% set(gca,'Xdir','reverse')
subplot(2,2,3) %bump velociy
hold all
plot(Fbump1(:,3,n), Fbump1(:,1,n)); % displacement
% set(gca,'Ydir','reverse')
% set(gca,'Xdir','reverse')
[xmx,loc] = max(Fbump1(:,3,n));
ymx = Fbump1(loc);
xmx_big(n)=xmx;
ymx_big(n)=ymx;
[xmn,loc1] = min(Fbump1(:,3,n));
ymn = Fbump1(loc1);
xmn_big(n)=xmn;
ymn_big(n)=ymn;
subplot(2,2,4) %rebound velocity
hold all
plot(Frebound1(:,3,n), Frebound1(:,1,n)); % displacement
% set(gca,'Ydir','reverse')
% set(gca,'Xdir','reverse')
end
Accepted Answer
More Answers (0)
Categories
Find more on Numerical Integration and Differentiation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!