matlab - 在 MATLAB 的 If 语句中使用多个条件的问题
问题描述
我遇到了一个问题,对于第一个 for 循环,我在 no2_iterate(1) 处获得了我想要的输出,但在生成 no2_iterate(2) 的第二个循环中,我没有得到任何输出。
以下是我生成 no2_iterate(1) & (2) 的两个 if 语句/for 循环。
no2_sum_1cm = 0;
gridh_iterate = 0 % starting height in cm
lato = 1;
lono = 1;
no2_iterate_start = 0;
no2_iterate(1:2) = 0;
if gridh_iterate < gridh(lato,lono,1);
no2_layer = no2_moleccm3(lato,lono,1,12);
for i = 1:gridh(lato,lono,1);
for h = 1;
gridh_iterate = gridh_iterate+ 1; % in cm, now compare to gridh(1,1,1) and the other areas, so if its over the height of the cell switch no2 concn
end
no2_iterate(1) = (no2_iterate(1) + no2_layer)*1; % Now units of g no2/cm2
end
no2_iterate = no2_iterate
end
if gridh_iterate < gridh(lato,lono,2) && gridh_iterate >gridh(lato,lono,1);
no2_layer = no2_moleccm3(lato,lono,2,12);
for i = 1:gridh(lato,lono,2);
for h = 1;
gridh_iterate = gridh_iterate + 1; % in cm, now compare to gridh(1,1,1) and the other areas, so if its over the height of the cell switch no2 concn
end
no2_iterate(2) = (no2_iterate(2) + no2_layer)*1; % Now units of g no2/cm2
end
no2_iterate = no2_iterate;
end
我怀疑我的问题在第二个 if 语句中,我在其中指定我希望范围在两个单独的变量之间,我以某种方式排除了所有变量。
解决方案
我最终找出了问题所在。这是解决我麻烦的代码!
还要感谢评论员帮助我清除了我的代码中的一些噪音,这些噪音没有做任何实际的事情。
no2_sum_1cm = 0;
gridh_iterate = 0 % starting height in cm
lato = 1;
lono = 1;
no2_iterate_start = 0;
no2_iterate(1:27) = 0;
if gridh_iterate <= gridh(lato,lono,1);
no2_layer = no2_moleccm3(lato,lono,1,12);
for i = 1:gridh(lato,lono,1);
gridh_iterate = gridh_iterate+ 1; % in cm, now compare to gridh(1,1,1) and the other areas, so if its over the height of the cell switch no2 concn
no2_iterate(1) = (no2_iterate(1) + no2_layer)*1; % Now units of g no2/cm2
end
end
gridh_iterate = 0;
if gridh_iterate <= gridh(lato,lono,2) %&& gridh_iterate>gridh(lato,lono,1);
no2_layer = no2_moleccm3(lato,lono,2,12);
for i = 1:gridh(lato,lono,2);
gridh_iterate = gridh_iterate + 1; % in cm, now compare to gridh(1,1,1) and the other areas, so if its over the height of the cell switch no2 concn
no2_iterate(2) = (no2_iterate(2) + no2_layer)*1; % Now units of g no2/cm2
end
end
我最终意识到,因为“网格”变量指定了单个单元格的高度而不是总高度,所以列出要保持的高度数据范围是无关紧要的,为了我的目的,我应该只设置网格单元格的高度我作为最大值很有趣,因此我的代码将遍历它然后停止。
推荐阅读
- javascript - VueJS:将图像文件位置数据绑定到 img 标签的 src 属性不起作用
- php - 来自 Exact Online 的对身份验证代码的 PHP OAuth 2.0 请求返回 __stripe_mid cookie
- compiler-errors - ESP32 编译探针
- php - 将gmail发送到公司电子邮件时出错(PHP)
- amazon-web-services - 如何使用 IAmazonDynamoDB 将空字符串作为 dynamodb dotnet 中的字段值传递?
- php - 如何使用 PHP for 循环将余额更新到下一条记录?
- r - 在R中的分组数据中保留变量的第一个值
- python - 实时共享变量。多进程 Python
- python - 如何对python中包含相同id的字典进行重复数据删除
- selenium - 在 selenium 中找到具有特定子 css 选择器的元素的以下同级