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

4 views (last 30 days)
Alex Myagkov
Alex Myagkov on 3 May 2022
Commented: Alex Myagkov on 3 May 2022
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).

Accepted Answer

Jonas
Jonas on 3 May 2022
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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by