Error plotting the spectrum with using user fucntion definition (Error using matlab.graphics.axis.Axes/set Invalid parameter/value pair argument)
4 次查看(过去 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!