Effacer les filtres
Effacer les filtres

Putting two FAS figures into one.

2 vues (au cours des 30 derniers jours)
Pepe
Pepe le 4 Mar 2021
Hello,
I am running fourier transform function for two datasets. The script below create two figures and I wonder how to modify to put both in a one plot.
Thanks in advance for any help.
Cheers,
Anna
% load recorded nodal data
acc = load ('/Users/annakowal/Documents/2D_site_analysis/flow_Hamilton/Taieri_2Dprofile/TEST11.out');
acc2 = load ('/Users/annakowal/Documents/2D_site_analysis/flow_Hamilton/Taieri_2Dprofile/TEST12.out');
time = acc(:,1);
time2 = acc2(:,1);
% remove time column from data
acc(:,1) = [];
acc2(:,1) = [];
% data descriptors
[nStep, nAcc] = size(acc);
nDOF = 2;
nNode = nAcc/nDOF;
[nStep2, nAcc2] = size(acc2);
nDOF2 = 2;
nNode2 = nAcc2/nDOF2;
% reshape data
a = reshape(acc, nStep, nDOF, nNode)/9.80665;
a2 = reshape(acc2, nStep2, nDOF2, nNode2)/9.80665;
dt=0.005; %time step
% FOURIER AMPLITUDE SPECTRUM
[f,U]=FAS(dt,a);
param.FAS = U;
param.freq = f;
[f,U]=FAS(dt,a2);
param.FAS = U;
param.freq = f;
function[f,U]=FAS(dt,a)
Ny = (1/dt)/2; %Nyquist frequency (highest frequency)
L = length(a); %number of points in acc
NFFT = 2^nextpow2(L); % Next power of 2 from length of acc
df = 1/(NFFT*dt); %frequency spacing
U = abs(fft(a,NFFT))*dt; %Fourier amplitudes
U = U(2:Ny/df+1); %single sided FAS
f = linspace(df,Ny,Ny/df)'; %[small, large, number] frequencies
figure;
plot(f,U,'-r','linewidth',1.5)
grid on
box on
xlabel('Frequency (Hz)','fontsize',16)
ylabel('Fourier Spectral Acceleration (g)','fontsize',16)
legend ('Fourier Amplitude Spectrum')
axis([0 10 -inf inf])
return
end

Réponses (2)

Star Strider
Star Strider le 4 Mar 2021
Use the hold function to put multiple plot calls in the same axes.
Example —
figure
plot(x1, y1)
hold on
plot(x2, y2)
plot(x3, y3)
hold off
grid
.

Walter Roberson
Walter Roberson le 5 Mar 2021
Modifié(e) : Walter Roberson le 5 Mar 2021
Remove the call
figure;
Add the call
hold on
after the plotting

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by