mercredi 20 février 2019

Iterating with if statements and for loops in MATLAB

I'm currently using matlab to calculate and sum the no2 at every cm along a vertical path of length "maxh".

I'm currently using the following code to specify not only the concentration of no2 at any height, but also the change in height.

My issue is I keep getting the error: "Undefined function or variable 'no2_iterate'. " which is the ultimate total amount of no2 over a vertical line through the atmosphere.

I imagine I might have a few problems, but i'm really just wondering why I'm getting an undefined measurement for my "no2_iterate" variable.

maxh = sum(gridh(1,1,1:27)) % Max height at a position

%For here, I want to gradually increase the height of the measurement by
%1cm over and over. For each 1cm swath I want to multiply the molecules/cm3
%by 1cm so I get the amount over that cm swath per 
no2_sum_1cm = 0;
gridh_iterate = 0 % starting height in cm
lato = 1;
lono = 1;

if gridh_iterate > gridh(lato,lono,1);
    no2_layer = no2_moleccm3(1,1,1,12);
elseif gridh_iterate >gridh(lato,lono,2);
    no2_layer = no2_moleccm3(1,1,2,12);
elseif gridh_iterate >gridh(lato,lono,3);
    no2_layer = no2_moleccm3(1,1,3,12);
elseif gridh_iterate >gridh(lato,lono,4);
    no2_layer = no2_moleccm3(1,1,4,12);
elseif gridh_iterate >gridh(lato,lono,5);
    no2_layer = no2_moleccm3(1,1,5,12);
elseif gridh_iterate >gridh(lato,lono,6);
    no2_layer = no2_moleccm3(1,1,6,12);
elseif gridh_iterate >gridh(lato,lono,7);
    no2_layer = no2_moleccm3(1,1,7,12);
elseif gridh_iterate >gridh(lato,lono,8);
    no2_layer = no2_moleccm3(1,1,8,12);
elseif gridh_iterate >gridh(lato,lono,9);
    no2_layer = no2_moleccm3(1,1,9,12);
elseif gridh_iterate >gridh(lato,lono,10);
    no2_layer = no2_moleccm3(1,1,10,12);
elseif gridh_iterate >gridh(lato,lono,11);
    no2_layer = no2_moleccm3(1,1,11,12);
elseif gridh_iterate >gridh(lato,lono,12);
    no2_layer = no2_moleccm3(1,1,12,12);
elseif gridh_iterate >gridh(lato,lono,13);
    no2_layer = no2_moleccm3(1,1,13,12);
elseif gridh_iterate >gridh(lato,lono,14);
    no2_layer = no2_moleccm3(1,1,14,12);
elseif gridh_iterate >gridh(lato,lono,15);
    no2_layer = no2_moleccm3(1,1,15,12);
elseif gridh_iterate >gridh(lato,lono,16);
    no2_layer = no2_moleccm3(1,1,16,12);
elseif gridh_iterate >gridh(lato,lono,17);
    no2_layer = no2_moleccm3(1,1,17,12);
elseif gridh_iterate >gridh(lato,lono,18);
    no2_layer = no2_moleccm3(1,1,18,12);
elseif gridh_iterate >gridh(lato,lono,7);
    no2_layer = no2_moleccm3(1,1,7,12);
elseif gridh_iterate >gridh(lato,lono,19);
    no2_layer = no2_moleccm3(1,1,19,12);
elseif gridh_iterate >gridh(lato,lono,20);
    no2_layer = no2_moleccm3(1,1,20,12);
elseif gridh_iterate >gridh(lato,lono,21);
    no2_layer = no2_moleccm3(1,1,21,12);
elseif gridh_iterate >gridh(lato,lono,22);
    no2_layer = no2_moleccm3(1,1,22,12);
elseif gridh_iterate >gridh(lato,lono,23);
    no2_layer = no2_moleccm3(1,1,23,12);
elseif gridh_iterate >gridh(lato,lono,24);
    no2_layer = no2_moleccm3(1,1,24,12);
elseif gridh_iterate >gridh(lato,lono,25);
    no2_layer = no2_moleccm3(1,1,25,12);
elseif gridh_iterate >gridh(lato,lono,26);
    no2_layer = no2_moleccm3(1,1,26,12);
elseif gridh_iterate >gridh(lato,lono,27);
    no2_layer = no2_moleccm3(1,1,27,12);
    for i = 1:maxh;
        for h = 1;
            gridh_iterate = gridh_iterature + 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 = (no2_iterate + no2_layer)*1 % Now units of g no2/cm2
    end
end

Best, Taylor

Aucun commentaire:

Enregistrer un commentaire