matlab中的风玫瑰图绘制
我目前正试图在matlab中绘制一个风玫瑰图,其中包含给定时期的风速和风向数据。 主程序是这样的,在威布尔分布上绘制了几个图之后,它调用另一个matlab程序来生成风玫瑰 wind rose计划的基本内容如下: 而主程序主要是基于 我昨天一直在编写一个非常旧的matlab版本,在运行代码时遇到了严重的问题。 今天,在Ubuntu机器上安装了Octave,经过一些努力,我终于在一个小问题上得到了一个结果:wind rose没有它应该拥有的所有信息 我在新版本的matlab中运行该程序,然后得到以下消息:matlab中的风玫瑰图绘制,matlab,weibull,Matlab,Weibull,我目前正试图在matlab中绘制一个风玫瑰图,其中包含给定时期的风速和风向数据。 主程序是这样的,在威布尔分布上绘制了几个图之后,它调用另一个matlab程序来生成风玫瑰 wind rose计划的基本内容如下: 而主程序主要是基于 我昨天一直在编写一个非常旧的matlab版本,在运行代码时遇到了严重的问题。 今天,在Ubuntu机器上安装了Octave,经过一些努力,我终于在一个小问题上得到了一个结果:wind rose没有它应该拥有的所有信息 我在新版本的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);
我不明白,这个程序怎么能在八度音阶下运行,现在却产生这样的错误
有人知道这个错误是什么意思吗
注意:如果有人想阅读,我将在下面发布完整的代码:
%% 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);
它是在进行选项参数清理的例程中生成的。由于选项必须以名称-值对的形式提供。。。脚本似乎检测到元素数量不匹配,一个或多个名称缺少值。这是:
选择权=
{'anglenorth','FreqLabelAngle',0,'angleeast','FreqLabelAngle',90,'labels',{N'
(0),"S(180),"E(90),"W
(270)},'frequelabelangle',45,'ndirection',20,'nFreq',25,'LegendType',1}
用粗体字体标记的两个属性没有关联的值(与教程中的示例不同),这可能会打乱整个参数化过程。可能提取的第一个选项是
anglenorth=frequelabelangle
,这是不正确的。请注意,所有绘图都是从较新版本的matlab中复制的,我只是在绘制风玫瑰图时遇到了问题。谢谢大家。如果我检查一下windrose.m,我觉得arrayfun中的@operator有什么问题吗?像这样的事情是可能的吗?我在Matlab2017下尝试过,它在默认示例中运行良好。这可能取决于你的数据。@TommasoBelluzzo好吧,我的数据给了我所有其他的图。。。就我所见,它们只是向量——如果你运行它,你已经看到了。你有什么特别的想法吗?或者,可能是一个包裹丢失了?谢谢。你的一个论点似乎是一个空字符串……好吧,如果这是问题所在(不知怎么的,八度音阶绕过了它),我真是太感谢你了。不幸的是,我现在无法访问matlab来验证您的说法,但似乎有理由相信您是正确的,这实际上是错误的根源。我会在9-10小时内检查密码,然后再打给你。不过,再次感谢你在这里所做的一切。它会运行的。现在我只需要想一想如何产生期望的结果。再次感谢大家,;你考虑得很好。