Putting two FAS figures into one.
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Star Strider
on 4 Mar 2021
Example —
figure
plot(x1, y1)
hold on
plot(x2, y2)
plot(x3, y3)
hold off
grid
.
0 Comments
Walter Roberson
on 5 Mar 2021
Edited: Walter Roberson
on 5 Mar 2021
Remove the call
figure;
Add the call
hold on
after the plotting
0 Comments
See Also
Categories
Find more on Specifying Target for Graphics Output 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!