Проблема использования нескольких критериев в операторах if в MATLAB - PullRequest
0 голосов
/ 21 февраля 2019

У меня проблема с тем, что для первого цикла for я получаю желаемый вывод в no2_iterate (1), но во втором цикле, созданном для генерации no2_iterate (2), я не получаю никакого вывода вообще.

Ниже приведены мои два цикла if-операторов / for для генерации no2_iterate (1) & (2).

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, где яукажите, что я хочу, чтобы диапазон находился между двумя отдельными переменными, которые я как-то исключаю из всех переменных.

1 Ответ

0 голосов
/ 21 февраля 2019

Я выяснил проблему.Вот код, который решил мои проблемы!

Также спасибо комментаторам за то, что они помогли мне убрать часть шума из моего кода, который не принес ничего практического.

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

Я закончилПонимание того, что переменные "gridh" задали высоту отдельной ячейки, а не общую высоту, что было неуместно перечислять диапазон данных о высоте, между которыми нужно оставаться, и что для моих целей я должен просто установить высоту ячейки сетки. Мне было интереснов качестве максимума, чтобы мой код проходил через него и затем прекращал работу.

...