matlab中的风玫瑰图

Wind rose diagram plot in matlab

我目前正在尝试在 matlab 中绘制风玫瑰图,其中包含给定时间段内的数据风速和风向。 主程序是这样的,在威布尔分布上绘制几个图后,它调用另一个 matlab 程序来产生风向图。

风玫瑰程序基本在这里:https://www.mathworks.com/matlabcentral/fileexchange/47248-wind-rose

而主程序主要是基于https://www.mathworks.com/matlabcentral/fileexchange/41996-computing-weibull-distribution-parameters-from-a-wind-speed-time-series?focused=3786165&tab=function

我昨天一直在研究一个非常旧的 matlab 版本,我在编写代码时遇到了严重的问题 运行。 今天在一台 Ubuntu 机器上使用 Octave,经过一些努力,我设法得到了一个有小问题的结果:风玫瑰没有它应该拥有的所有信息。

我运行在新版本的matlab中运行程序,然后我收到以下消息:

Error using WindRose (line 244)
 is not a valid property for WindRose function.
Error in octavetestoforiginalprogram (line 184)
[figure_handle,count,speeds,directions,Table] = WindRose(dir,vel,Options); 

Octave和现在的程序运行怎么会产生这样的错误,我不明白。

有人知道这个错误是什么意思吗?

注意:如果有人想阅读,我将在下面发布完整代码:

%% EXTRACT AND PLOT RAW DATA

% Extract wind speed data from a file
v = xlsread('1981-1985_timeseries.xlsx');

% Plot the measured wind speed
plot(v)
title('Wind speed time series');
xlabel('Measurement #');
ylabel('Wind speed [m/s]');





%% PROCESS DATA

% Remove nil speed data (to avoid infeasible solutions in the following)
v(find(v==0)) = [];
% Extract the unique values occuring in the series
uniqueVals = unique(v);
uniqueVals(isnan(uniqueVals))=[];

% Get the number of unique values
nbUniqueVals = length(uniqueVals);

% Find the number of occurences of each unique wind speed value
for i=1:nbUniqueVals
    nbOcc = v(find(v==uniqueVals(i)));
    N(i) = length(nbOcc);
end

% Get the total number of measurements
nbMeas = sum(N);

% To take into account the measurement resolution
% (i.e., a measured wind speed of 2.0 m/s may actually correspond to a
% real wind speed of 2.05 or 1.98 m/s), compute the delta vector which
% contains the difference between two consecutive unique values
delta(1) = uniqueVals(1);
for i=2:nbUniqueVals
    delta(i) = uniqueVals(i) - uniqueVals(i-1);
end

% Get the frequency of occurence of each unique value
for i=1:nbUniqueVals
    prob(i) = N(i)/(nbMeas*delta(i));
end



% Get the cumulated frequency
freq = 0;
for i=1:nbUniqueVals
    freq = prob(i)*delta(i) + freq;
    cumFreq(i) = freq;
end


%% PLOT THE RESULTING DISTRIBUTION

% Plot the distribution
figure
subplot(2,1,1);
pp=plot(uniqueVals,prob)
title('Distribution extracted from the time series');
xlabel('Wind speed [m/s]');
ylabel('Probability');

% Plot the cumulative distribution
subplot(2,1,2);
plot(uniqueVals,cumFreq)
title('Cumulative distribution extracted from the time series');
xlabel('Wind speed [m/s]');
ylabel('Cumulative probability');


%% EXTRACT THE PARAMETERS USING A GRAPHICAL METHOD

% See the following references for more explanations:
% - Akdag, S.A. and Dinler, A., A new method to estimate Weibull parameters
% for wind energy applications, Energy Conversion and Management,
% 50 :7 1761�1766, 2009
% - Seguro, J.V. and Lambert, T.W., Modern estimation of the parameters of
% the Weibull wind speed distribution for wind energy analysis, Journal of
% Wind Engineering and Industrial Aerodynamics, 85 :1 75�84, 2000


% Linearize distributions (see papers)
ln = log(uniqueVals);
lnln = log(-log(1-cumFreq));

% Check wether the vectors contain inifinite values, if so, remove them
test = isinf(lnln);
for i=1:nbUniqueVals
    if (test(i)==1)
        ln(i)= [];
        lnln(i)= [];
    end
end

% Extract the line parameters (y=ax+b) using the polyfit function
params = polyfit(ln,lnln',1);
a = params(1);
b = params(2);
y=a*ln+b;

% Compare the linealized curve and its fitted line
figure
plot(ln,y,'b',ln,lnln,'r')
title('Linearized curve and fitted line comparison');
xlabel('x = ln(v)');
ylabel('y = ln(-ln(1-cumFreq(v)))');

% Extract the Weibull parameters c and k
k = a
c = exp(-b/a)


%% CHECK RESULTS

% Define the cumulative Weibull probability density function
% F(V) = 1-exp(-((v/c)^k)) = 1-exp(-a2), with a1 = v/c, a2 = (v/c)^k
a1 = uniqueVals/c;
a2 = a1.^k;
cumDensityFunc = 1-exp(-a2); 

% Define the Weibull probability density function
%f(v)=k/c*(v/c)^(k-1)*exp(-((v/c)^k))=k2*a3.*exp(-a2), 
% with  k2 = k/c, a3 = (v/c)^(k-1)
k1 = k-1;
a3 = a1.^k1;
k2 = k/c;
densityFunc = k2*a3.*exp(-a2);  

% Plot and compare the obtained Weibull distribution with the frequency plot
figure
subplot(2,2,1);
pp=plot(uniqueVals,prob,'.',uniqueVals,densityFunc, 'r')
title('Weibull probability density function');
xlabel('v');
ylabel('f(v)');

subplot(2,2,3)
h=hist(v);
title('Wind speed time series');
xlabel('Measurement #');
ylabel('Wind speed [m/s]');
h=h/(sum(h)*10);
bar(h)

% Same for the cumulative distribution
subplot(2,2,2);
plot(uniqueVals,cumFreq,'.',uniqueVals,cumDensityFunc, 'r')
title('Cumulative Weibull probability density function');
xlabel('v');
ylabel('F(V)');


%inner
figure
hold on
pp=plot(uniqueVals,prob,'.',uniqueVals,densityFunc, 'r')
title('Weibull probability density function');
xlabel('v');
ylabel('f(v)');

bar(h)

hold off

%inner



%rose

w=xlsread('rose.xlsx');
dir=w(:,2)*10;
vel=w(:,1);

Options = {'anglenorth','FreqLabelAngle',0,'angleeast','FreqLabelAngle',90,'labels',{'N (0)','S (180)','E (90)','W (270)'},'freqlabelangle',45,'nDirections',20,'nFreq',25,'LegendType',1};
[figure_handle,count,speeds,directions,Table] = WindRose(dir,vel,Options);

close all; clear Options;

快速阅读脚本文档后,我发现了有关创建 windrose 情节的内容:

% With options in a cell array:
Options = {'anglenorth',0,'angleeast',90,'labels',{'N (0°)','S (180°)','E (90°)','W (270°)'},'freqlabelangle',45};
[figure_handle,count,speeds,directions,Table] = WindRose(dir,spd,Options);

% With options in a structure:
Options.AngleNorth     = 0;
Options.AngleEast      = 90;
Options.Labels         = {'N (0°)','S (180°)','E (90°)','W (270°)'};
Options.FreqLabelAngle = 45;
[figure_handle,count,speeds,directions,Table] = WindRose(dir,spd,Options);
close all;

% Usual calling:
[figure_handle,count,speeds,directions,Table] = WindRose(dir,spd,'anglenorth',0,'angleeast',90,'labels',{'N (0°)','S (180°)','E (90°)','W (270°)'},'freqlabelangle',45);

你的错误是:

Error using WindRose (line 244)
 is not a valid property for WindRose function.

Error in octavetestoforiginalprogram (line 184)
[figure_handle,count,speeds,directions,Table] = WindRose(dir,vel,Options);

并且它在进行选项参数清理的例程中生成。由于选项必须以 name-value 对的形式提供...似乎脚本正在检测不匹配的元素数量和一个或多个具有缺失值的名称。他们在这里:

Options = {'anglenorth','FreqLabelAngle',0,'angleeast','FreqLabelAngle',90,'labels',{'N (0)','S (180)','E (90)','W (270)'},'freqlabelangle',45,'nDirections',20,'nFreq',25,'LegendType',1};

用粗体标记的两个属性没有关联值(与教程中的示例不同),这可能会扰乱整个参数化过程。可能提取的第一个选项是 anglenorth = FreqLabelAngle,这是不正确的。