Error plotting the spectrum with using user fucntion definition (Error using matlab.gra​phics.axis​.Axes/set Invalid parameter/value pair argument)

조회 수: 1 (최근 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).

채택된 답변

Jonas
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 CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by