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 Center および File ExchangeDirected Graphs についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by