Error: Invalid parameter/value pair arguments.
조회 수: 70 (최근 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!