How do i only plot last vector

4 次查看(过去 30 天)
hi, I'm trying to plot a speed and position fft but when I do the graph it plots all the lines but I just need the last one
clear all;clf;
data = readmatrix('2240.csv');
tempo = data(:,1);
ultima = data(end,1); %%ultimo valor de tempo de coleta
T = ultima; %tempo final da simulação
N = length(tempo); %T*100; %número de pontos entre 0 e T
t = tempo; %linspace(0,T,N);
dt= mean(diff(tempo)); %T/N;
df=1/T; fs=1/dt;
y=data(:,2); %4*sin(2*pi*5*t)+2*sin(2*pi*8*t); %função no tempo em 5Hz e 8Hz amplitudes 4 e 2.
figure(1)
plot(t,y,'b-',t,y,'r');
xlabel('tempo [s]');ylabel('aceleracao [m/s^2]');xlim([0,T])
Ytemp = fft(y-mean(y))/(N/2); %fft(y-mean(y))/(N/2); %FFT
Y=Ytemp(1:floor(N/2));
f= linspace(0,df*(N/2),N/2); %linspace(0,df*(N/2),N/2); 1/(dt*N)*(0:N-1);
figure(2)
subplot(3,1,1)
plot(f,abs(Y));
xlabel('frequencia [Hz]');ylabel('aceleracao [m/s^2]');
%iniciar FFT de velocidade e posição a partir de 1 Hz (denominador de vel e posição não deve ser zero).
inicio = find(f>1,1);
vel = 1000*abs(Y(inicio:end))./(2*pi*f(inicio:end));
subplot(3,1,2)
plot(f(inicio:end),vel);
xlabel('frequencia [Hz]');ylabel('velocidade [mm/s]');
posicao = 1000*abs(Y(inicio:end))./((2*pi*f(inicio:end)).^2);
subplot(3,1,3)
plot(f(inicio:end), posicao);
xlabel('frequencia [Hz]');ylabel('posiçao [mm]');
  1 个评论
Walter Roberson
Walter Roberson 2022-8-9
data = readmatrix('2240.csv');
tempo = data(:,1);
ultima = data(end,1); %%ultimo valor de tempo de coleta
T = ultima; %tempo final da simulação
N = length(tempo); %T*100; %número de pontos entre 0 e T
t = tempo; %linspace(0,T,N);
dt= mean(diff(tempo)); %T/N;
df=1/T; fs=1/dt;
y=data(:,2); %4*sin(2*pi*5*t)+2*sin(2*pi*8*t); %função no tempo em 5Hz e 8Hz amplitudes 4 e 2.
Ytemp = fft(y-mean(y))/(N/2); %fft(y-mean(y))/(N/2); %FFT
Y=Ytemp(1:floor(N/2));
f= linspace(0,df*(N/2),N/2); %linspace(0,df*(N/2),N/2); 1/(dt*N)*(0:N-1);
%iniciar FFT de velocidade e posição a partir de 1 Hz (denominador de vel e posição não deve ser zero).
inicio = find(f>1,1);
vel = 1000*abs(Y(inicio:end))./(2*pi*f(inicio:end));
posicao = 1000*abs(Y(inicio:end))./((2*pi*f(inicio:end)).^2);
plot(f(inicio:end), posicao);
xlabel('frequencia [Hz]');ylabel('posiçao [mm]');

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by