下标索引必须是实数正整数还是逻辑数? [英] Subscript indices must either be real positive integers or logicals?

查看:68
本文介绍了下标索引必须是实数正整数还是逻辑数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用for循环绘制Matlab程序的结果,该循环从1到10以0.1的增量运行.但是,当我尝试运行我的代码时,出现以下错误:

I am trying to plot the results of my Matlab programme using a for loop which operates from 1 to 10 in increments of 0.1. However I am getting the following error when I attempt to run my code:

下标索引必须是实数正整数或逻辑值.

错误(第101行) store_sigma(:,TSR)= sigma;

Error in BEM (line 101) store_sigma(:,TSR)=sigma;

这是我的完整代码:

% Inputs
R=0.4;                                          % Radius of Rotor
B=3;                                            % Number of blades
U=1.73;                                            % Fluid velocity
Rho=998;                                        % Fluid Density
N=9;                                            % Number of Blade Elements
Cp_estimate=0.5;                                % Estimate power coefficient
Alpha_design=4;                                 % Design alpha
Cl_design=1;                                    % Design lift coefficient
angular_velocity=22.92;


% Variables

i=1;                                            % Counter
alpha_new=0;                                    % Initial value for alpha new
tolerance=0.00001;                                 % Tolerance Value
axial_induction=[0,0,0,0,0,0,0,0,0];
Check=1;                                        % Initial check value
axial_induction_old=0;                          % Initial value for old axial induction factor


Cl=[1.3; 1.1; 1; 0.9; 0.86; 0.83; 0.8; 0.75; 0.5];                                          % Lift Coefficients
Cd=[0.027; 0.024; 0.02; 0.019; 0.018; 0.016; 0.013; 0.012; 0.01];                           % Drag Coefficients

r_local=R/9*(1:9)';
r_over_R=r_local / R;




for TSR=1:.1:10                                     % TSR from 1 to 10
    disp(TSR)                                                                    
    Check=1;



TSR_local=r_over_R .* TSR;    
Phi=(2/3)*atan(1./TSR_local);
C=((8*pi.*r_local) ./ (B.*Cl_design)).*(1-cos(Phi));
sigma=(B*C) ./ (pi.*r_local.*2);



axial_induction= 1 ./ (((4.*(sin(Phi).^2)) ./ (sigma.*Cl_design.*cos(Phi)))+1);
angular_induction= (1-(3*axial_induction)) ./ ((4.*axial_induction)-1);



relative_wind = (U.*(1-axial_induction))./(angular_velocity*R).*(1+angular_induction);

F=(2/pi) .* acos(exp(-(((B/2) .* (1-(r_over_R))) ./ ((r_over_R) .* sin(relative_wind)))));      % Tip Loss Factor

C_T=(sigma .* ((1-axial_induction).^2) .* ((Cl.*cos(relative_wind))+(Cd.*sin(relative_wind)))) ./ ((sin(relative_wind)).^2);

   while abs(Check)>=tolerance


axial_induction_old = axial_induction;        
TSR_local = TSR .* (r_local./R);                                                                 % Local Tip Speed Ratio
Phi = (2/3) .* atan(1./TSR_local);                                                               % Angle of Relative Fluid



for i=1:length(C_T)
   if  C_T(i) > 0.96;
      axial_induction(i) = 1 / (((4*F(i)*cos(relative_wind(i))) / (sigma(i)*Cl(i)))-1);

   else
       axial_induction(i) = 1 / (1+(4*F(i)*(sin(relative_wind(i))^2)) / (sigma(i)*Cl(i)*cos(relative_wind(i)))); 
   end;
end;




D=(8./(TSR.*9)).*(F.*(sin(Phi).^2).*(cos(Phi)-((TSR_local).*(sin(Phi)))).*(sin(Phi)+((TSR_local).*(cos(Phi)))).*(1-(Cd./Cl).*cot(Phi)).*(TSR_local.^2));
Cp=sum(D);


Diff=axial_induction-axial_induction_old;
Check=max(Diff(:));
Check

   end



store_sigma(:,TSR)=sigma;
store_Phi(:,TSR)=Phi;
store_TSR_local(:,TSR)=TSR_local;
store_axial_induction(:,TSR)=axial_induction;
store_angular_induction(:,TSR)=angular_induction;
store_relative_wind(:,TSR)=relative_wind;
store_Check(:,TSR)=Check;
store_Diff(:,TSR)=Diff;
store_Cp(:,TSR)=Cp;
store_TSR(:,TSR)=TSR;
store_F(:,TSR)=F;

end

有人知道如何索引存储的值,以便可以在for循环的增量步骤中使用整数值吗?

Does anybody have any idea of how I could index my stored values so that I can use an interger value for my incremental steps inside the for loop?

谢谢.

推荐答案

您可以使用此简单技巧:将TSR的值与循环索引分开.
例如:

You can use this simple trick: separate the value of TSR from the loop index.
For example:

TSRs = 1:.1:10
for TSR_index = 1:numel(TSRs)
    TSR = TSRs( TSR_index );
    % continue your computation here using TSR

    % when saving values use TSR_index, e.g.:
    store_sigma(:,TSR_index)=sigma;

end

这篇关于下标索引必须是实数正整数还是逻辑数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆