MATLAB if loop,element and arrey

%e_r_z loop
for e_r_z=1:length(ratio)
    if ratio(e_r_z)> 1.4
        eta1(e_r_z)= 1.32/(1+ratio(e_r_z));
    elseif ratio(e_r_z)< 0.06
        eta1(e_r_z)= 1.0;
    else
        % approximation
        eta1(e_r_z)= interp1([0.05 0.2 0.4 0.7 1.5],[1.0 0.9 0.8 0.7 0.4],ratio(e_r_z),'linear');
    end
end

%Non e_r_z loop
if ratio> 1.4
    eta2= ratio+5;
elseif ratio< 0.06
    eta2= ratio-10;
else
    eta2=ratio+10;
end

The upper program, caulate the single element.
The lower one, caulate the whole arrey:
maybe compare the every element of ratio arrey with the value(1.4/0.06) from beginning to the end, just like the upper program(e_r_z loop), find not every element of the arrey is greater than 1.4 or less than 0.06. So, make the choice else, then, eta2=ratio+10;, so, when come to the end of the program , every element of eta2 is added with 10, which means the elements which are greater than 1.4 and less than 0.06 also was added by 10.

So, if you want to agree the condition of one if loop, if ratio> 1.4, eta2= ratio+5; it need every elements of the ratio arrey meet the condition.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值