【发布时间】:2019-02-20 22:02:47
【问题描述】:
我遇到了一个问题,对于第一个 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 语句中,我在其中指定我希望范围在两个单独的变量之间,我以某种方式排除了所有变量。
【问题讨论】:
-
for h = 1;的目的是什么?no2_iterate = no2_iterate也毫无意义。如果你能解释你试图实现的方程式,它可能更容易提供帮助。我看不到您要计算的内容。还请包括gridh(lato,lono,:)和no2_moleccm3(lato,lono,:,12);的内容,这些值用于计算,需要定义以便我复制粘贴和运行您的代码。见minimal reproducible example。
标签: matlab loops for-loop if-statement