Error: Invalid parameter/value pair arguments.

63 ビュー (過去 30 日間)
tara es
tara es 2022 年 10 月 19 日
コメント済み: tara es 2022 年 10 月 20 日
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])

採用された回答

dpb
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.
  1 件のコメント
tara es
tara es 2022 年 10 月 20 日
Thanks! It work well.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by