Error: Invalid parameter/value pair arguments.
66 次查看(过去 30 天)
显示 更早的评论
Hi there, this code return (Invalid parameter/value pair arguments ) error. Is there any problem with using 'color'? how can I fix it?
clc
clear
close all
format long g
%% read
fid = xlsread('WINT.csv');
f = fid(:, 1);
for i = 1:size(north)
for j=1
t(i,j)=i;
end
end
Y = fft(f) ;
dt = mean(diff(t)) ;
fs = 1./(dt*24) ;
L = length(f) ;
ft = fs*(0:L/2)/L ;
P2 = abs(Y/L) ;
P1 = P2(1:L/2+1) ;
P1(2:end-1) = 2*P1(2:end-1) ;
P1 = P1.^2 ;
period = (1./ft)/24 ;
freq = 600 ;
figure
plot(ft*1e9, P1, 'color','b')
xlabel('Frequency [nHz]')
ylabel('PSD')
title('Fourier spectrum')
set(gca, 'XScale', 'log')
xline((1/(freq*24*60*60))*1e9,'color',[125,0,251]/255 , [num2str(freq), ' days'])
set(gca, 'YLim', [0, 40])
0 个评论
采纳的回答
dpb
2022-10-19
" Is there any problem with using 'color'?"
In
xline((1/(freq*24*60*60))*1e9,'color',[125,0,251]/255 , [num2str(freq), ' days'])
yes, there is. The named parameters for xline must follow the last of the input parameters and the second, must be a linespec character or string variable if the third for the label is used. It isn't flexible-enough in parsing inputs to mix up the order. To use a color triplet and the name as an argument, you need to write the above as
xline((1/(freq*24*60*60))*1e9,'-',[num2str(freq),' days'],'color',[125,0,251]/255)
where the linespec is the linestyle '-' character.
One slight difference that makes the name a little simpler could be to use the new(ish) string class that overloads the plus operator--
xline((1/(freq*24*60*60))*1e9,'-',freq+" days",'color',[125,0,251]/255)
NOTA BENE: the use of the " double quotes around the string constant.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!