Putting two FAS figures into one.

조회 수: 1 (최근 30일)
Pepe
Pepe 2021년 3월 4일
편집: Walter Roberson 2021년 3월 5일
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

답변 (2개)

Star Strider
Star Strider 2021년 3월 4일
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 2021년 3월 5일
편집: Walter Roberson 2021년 3월 5일
Remove the call
figure;
Add the call
hold on
after the plotting

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by