查找轮廓图最大值的位置

时间:2019-04-05 14:13:15

标签: matlab contour

我已经弄清楚了大部分代码,但是我不知道在x()和y()代码末尾的括号中要插入什么,以找到轮廓中最大值的位置

这是由我的教授预先编写的Matlab代码,我必须填写其中的大部分空白。我对MATLAB不熟悉,所以我不知道x()和y()的意义是什么。我也尝试过研究MATLAB指南。

% Project: Modeling pollutant concentration with Gaussian model
% The Table numbers refer to the handouts on "Air Pollution", available on BB

clear
clc

% input variables
Q= 500*10^6 ; %source emission rate (ug/s)
H=120  ; %effective stack height (m)


% define spatial domain
xlength= 10000;  % domain length (m) --> 10km
ylength= 4000;  % domain width (m) --> 2 km on either side of the plume centerline
dx= 100;        % x node spacing (m)
dy= 100;        % y node spacing (m)
x=0:dx:xlength; %(m)
x(1)=1;
y=-ylength/2:dy:ylength/2; %(m)


% calculate windspeed at z=H for stability classes A, C, F
% ground-level windspeeds (at z=10 m)
GLwindspeed=[2 2 2]; %(m/s)


% uH/ua=(H/za)^p, so uH=ua*(H/za)^p. ua=anemometer height=GLwindspeed
% exponent p varies with stability class

p=[0.15 0.20 0.60]; % from Table 7.6
za=  10 ; % standard anemometer height, (m)


for i=1:3 % # of stability classes to be considered
    uH(i)=GLwindspeed(i)*(H/za)^p(i); %wind speed at effective stack height (m)
end


% coefficients a, c, d, f for calculation of sigma y and z (Table 7.8)
coeff_a=[213 104 34]; % coefficient a doesn't depend on the downwind distance x 
coeff_c=[440.8 61.0 14.35 ; 459.7 61.0 62.6]; % different coefficients for x<=1km and x>1km
coeff_d=[1.941 0.911 0.740 ; 2.094 0.911 0.180];  % different coefficients for x<=1km and x>1km
coeff_f=[9.27 0 -0.35 ; -9.6 0 -48.6];  % different coefficients for x<=1km and x>1km


%calculate the pollutant concentration C for entire domain (and the three stability classes)

for st=1:3  % st = # of stability class (A, C, F)

    for i=1:length(x)

        sigmaY=coeff_a(st)*(x(i)/1000)^0.894; % coefficients of sigma Y  doesn't depend on the downwind distance x 

        % parameters in the empirical formula for sigma Z depend on the downwind distance x: 
        if x(i)<=1000 %(m)
            sigmaZ=coeff_c(1,st)*(x(i)/1000)^coeff_d(1,st)+coeff_f(1,st);
        else
            sigmaZ=coeff_c(2,st)*(x(i)/1000)^coeff_d(2,st)+coeff_f(2,st);
        end

        for j=1:length(y)

            C(i,j,st)=Q/(pi*sigmaY*sigmaZ*uH(st))*exp(-y(j)^2/(2*sigmaY^2))*2*exp(-H^2/(2*sigmaZ^2));

        end
    end
end


% Contour Plots
for st=1:3
    figure
    contour(y,x,C(:,:,st))
    colorbar
    title('Downwind Pollutant Concentration','FontSize',18)
    xlabel('Downwind Width (m)','FontSize',18);
    ylabel('Downwind Distance (m)','FontSize',18)
    set(gca,'FontSize',12)
end

% Peak concentrations:
peak_classA= max(max(C(:,:,1)))
peak_classC= max(max(C(:,:,2)))
peak_classF= max(max(C(:,:,3)))

% Location of peak concentrations:
[iA,jA]=find(C(:,:,1)==peak_classA);
x(   )
y(   )

[iC,jC]=find(C(:,:,2)==peak_classC);
x(   )
y(   )

[iF,jF]=find(C(:,:,3)==peak_classF);
x(   )
y(   )

1 个答案:

答案 0 :(得分:0)

'find'命令返回一个索引,使用该索引我们可以找到x和y值。

% Location of peak concentrations:
[iA,jA]=find(C(:,:,1)==peak_classA);
x(iA) %Finds the x value at the index iA
y(jA) %Finds the y value at the index jA

[iC,jC]=find(C(:,:,2)==peak_classC);
x(iC)
y(jC)

[iF,jF]=find(C(:,:,3)==peak_classF);
x(iF)
y(jF)

对于A类,此返回

ans =

   400


ans =

     0

检查图,(0,400)似乎合适!

plot1