Cannot add line to magnitude graph after FFT

조회 수: 2 (최근 30일)
Sam
Sam 2024년 9월 8일
답변: Shivansh 2024년 9월 8일
I tried to use FFT to transfer a time domain data to frequency domain, and it appear two graphs (magnitude against frequency and phrase against frequency). I want to hide phrase graph and add a vertical line to the magnitude graph. However, the line only add to the phrase graph even I have hidden it. Could any talented matlab user advise how can I add the vertical line to the magnitude graph? Thank you!
T = 0.001
G3data1 = iddata(G3x1,[],T)
G3data2 = iddata(G3x2,[],T)
G3data3 = iddata(G3x3,[],T)
G3data4 = iddata(G3x4,[],T)
M3f1 = fft(G3data1)
M3f2 = fft(G3data2)
M3f3 = fft(G3data3)
M3f4 = fft(G3data4)
M3f = merge(M3f1, M3f2, M3f3, M3f4,N)
opt = dataPlotOptions('frequency');
opt.PhaseVisible = 'off';
opt.Xlim = [1 50];
opt.FreqUnits = 'Hz';
opt.FreqScale = 'linear';
plot(M3f,opt)
xline(5)
title('Frequency Graph')
legend({'data1','data2','data3','data4'})

답변 (1개)

Shivansh
Shivansh 2024년 9월 8일
Hi Sam,
You can add a vertical line to the magnitude graph while hiding the phase graph by adding the line to the correct axes.
You can refer to the following code snippet for reference:
% Plot the data with phase hidden
plot(M3f, opt);
% Get handles to the axes
ax = gca; % Get current axes, assuming it's the magnitude plot
% Add a vertical line to the magnitude plot
xline(ax, 5);
% Customize the plot
title(ax, 'Frequency Graph');
legend(ax, {'data1', 'data2', 'data3', 'data4'});
I hope this resolves the issue!

카테고리

Help CenterFile Exchange에서 Directed Graphs에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by