Error plotting the spectrum with using user fucntion definition (Error using matlab.graphics.axis.Axes/set Invalid parameter/value pair argument)
2 ビュー (過去 30 日間)
古いコメントを表示
I try to plot power spectrum and create custom function to signal analyzer. First of my step is create plotting function psplot2.m
function psplot2(X1, Y1)
% psplot2(X1, Y1)
% X1: vector of plot x data
% Y1: vector of plot y data
% Create figure
figure1 = figure;
% Create axes
axes1 = axes('Parent',figure1);
hold(axes1,'on');
% Create plot
plot(X1,Y1,'LineWidth',1,'Color',[0 0 1]);
% Create ylabel
ylabel('Amplitude','FontName','Arial');
% Create xlabel
xlabel('Freq, kHz','FontName','Arial');
% Uncomment the following line to preserve the Y-limits of the axes
ylim(axes1,[0 80]);
grid(axes1,'on');
hold(axes1,'off');
% Set the remaining axes properties
set(axes1,'ContextMenu','FontName','Arial','GridAlpha',0.2,'GridLineStyle',...
'--','TickDir','out','XTickLabel',...
{'0', '10', '20','30','40', '50','60', '70', '80'});
And when I try to call this function file
n = length(sig1);
y = fft(sig1);
freq = 80e3;
fs = (0:n-1)*(freq/n);
power = abs(y).^2/n;
psplot2(fs,power)
get the same error:
Error using matlab.graphics.axis.Axes/set
Invalid parameter/value pair arguments.
Error in psplot2 (line 29)
set(axes1,'ContextMenu','FontName','Arial','GridAlpha',0.2,'GridLineStyle',...
Error in test_spetcrum (line 16)
psplot2(fs,power)
How to fix this error? Maybe I wrong get axis properties or figure axis properties? I read documentation for "axes", but it is not working.
Sample of my signals data (sig1.mat).
0 件のコメント
採用された回答
Jonas
2022 年 5 月 3 日
the problem is the part set(axes1,'ContextMenu'), which is not a valid Name-Value pair, leave out 'ContextMenu', since it appears you do not want to set this property to anything specific
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!