How to get range of values from a plot?

57 visualizaciones (últimos 30 días)
Susmita Panda
Susmita Panda el 4 de Abr. de 2021
Comentada: Susmita Panda el 20 de Abr. de 2021
Firstly, I am doubful about getting velocity and acceleration using 'gradient' function instead of 'diff' to get velocity and acceleration from displacement 'y2' in time domain.Is it the correct way to do? secondly, I am trying to get specific range of values from my graph but have no idea how to do?
For example, I just want values in time domain with 0 to 2.5 in x-axis or in between 2.5 to 10, and interpolate to get the perfect nearest one in time axis? I want such portion because I want to add another section of graph from free vibration analysis, this the the response using forced vibration only.
Here is my code:
clear all
close all
a=0.5;beta=0.025;wb=14.25;gamma = 1e-10; % introduce gamma
% Define time and frequency axis variables
fs =400; % samples/s
N = 1e6; % number of points
dt = 1 / fs; % s, time step
t = (0:N-1)*dt; % s, time axis
df = 1 / N / dt; % Hz, frequency step
f = (-N/2:N/2-1)*df; % Hz, frequency axis
% Define function first mode
for j=1:len_eta
yy = (y3+y4)/2;
%plot original signal
% plot initial time domain signal
plot(f,yy),title('Frequency response');ylabel('Displacement Response of beam');xlabel('Frequency');
grid on
%conversion to time domain
y2 = ifft(ifftshift(yy));
plot(t,(y2)),title('Time response');ylabel(' Displacement Response of beam');xlabel('Time');hold on;
axis([0 2.5 -0.03 0.03]); % time domain signal after IFFT
grid on
%% To calculate velocity and acceleration
figure(3),plot(t,(v)),title('Time response');ylabel('velocity Response of beam');xlabel('Time');hold on;
axis([0 2.5 -0.001 0.001]);
figure(4),plot(t,(acc)),title('Time response');ylabel('acceleration Response of beam');xlabel('Time');%hold on;
axis([0 2.5 -0.00002 0.00002]);
for k=1:9
plot(t,X_store(k,:),'color',cmap(k,:),'linewidth',1.5);axis([0 0.7 -0.03 0.03]); hold on;colorbar
hold off;
  6 comentarios
Susmita Panda
Susmita Panda el 5 de Abr. de 2021
Editada: Susmita Panda el 5 de Abr. de 2021
Sorry for inconvenience, but I modified my code....there was no use of T ....I just included to check some value.Please have a look now and suggest is it the right way to find acceleration and velocity and how to get half portion of result so that I can add next portion to it.
Susmita Panda
Susmita Panda el 5 de Abr. de 2021
I want to add the following reults to figure(5):
function dy=testode2(~,y)
global m k c
clear all;
close all;
global m k c
y0=[4.619*10^(-5) 0.021];
%%plot (displ vs time)
figure(1),plot(t,ysol(:,2));title('Displacement vs Time');
grid on
%%plot (velocity vs time)
figure(2),plot(t,ysol(:,1));title('Velocity vs Time')
grid on

Iniciar sesión para comentar.

Respuesta aceptada

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato el 18 de Abr. de 2021
The difference between gradient and diff is that the first calculates central differences and the second forward differences, both should give you an approximated right differentiation, although their numerical stabilities are different. In your case it shouldn't matter too much. Specifically for the case of displacement, velocity and acceleration, what is often done is a differentiation/integration in frequency domain. This can be done by multiplying/dividing your spectrum by 1j*w, where w = 2*pi*f.
If you only want the values between 0 and 2.5 s or any other interval you can find the respectively values by using logic indexing like this:
a=0.5;beta=0.025;wb=14.25;gamma = 1e-10; % introduce gamma
% Define time and frequency axis variables
fs =400; % samples/s
N = 1e6; % number of points
dt = 1 / fs; % s, time step
t = (0:N-1)*dt; % s, time axis
startTime = 0;
endTime = 2.5;
validIndices = find(t>startTime & t<endTime);
tTruncated = t(validIndices);
y2Truncated = t(validIndices);
validIndices = 1×999
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
To interpolate values in between you can take a look at the interp1 function.
  1 comentario
Susmita Panda
Susmita Panda el 20 de Abr. de 2021
How to add this portion of graph (0 to 0.7 axis values) to the other section ? Help is highly appreciated.

Iniciar sesión para comentar.

Más respuestas (0)


Más información sobre Data Distribution Plots en Help Center y File Exchange.




Community Treasure Hunt

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

Start Hunting!

Translated by