Convert aggregated measures to dimensions in tableau - tableau-api

I have created a calculated field [Segment] using the below codes. CalculationZ is also a calculated field. I need to convert the calculated field Segment to
a dimension. Is it possible in tableau. Please share the codes or formula/ methods to achieve this
IF [CalculationZ] < 0.10 THEN
"A1"
ELSEIF [CalculationZ] >= 0.10 and [CalculationZ] < 0.20 THEN
"A2"
ELSEIF [CalculationZ] >= 0.20 and [CalculationZ] < 0.30 THEN
"A3"
ELSEIF [CalculationZ] >= 0.30 and [CalculationZ] < 0.40 THEN
"A4"
ELSEIF [CalculationZ] >= 0.40 and [CalculationZ] < 0.50 THEN
"A5"
ELSEIF [CalculationZ] >= 0.50 and [CalculationZ] < 0.60 THEN
"A6"
ELSEIF [CalculationZ] >= 0.60 and [CalculationZ] < 0.70 THEN
"A7"
ELSEIF [CalculationZ] >= 0.70 and [CalculationZ] < 0.80 THEN
"A8"
ELSEIF [CalculationZ] >= 0.80 and [CalculationZ] < 0.90 THEN
"A9"
ELSEIF [CalculationZ] >= 0.90 and [CalculationZ] <= 1.00 THEN
"A10"
else "A0"
END

Just drag the field to dimensions.
You can even use a field as measure and dimension in a single view. See how calculationZ is used as a dimension and measure in below view.

Related

Writing a MATLAB code using an algorithm for a reciprocal matrix

I want to write a code for the following algorithm using MATLAB.
**Input:** An square reciprocal matrix T = (tij) for (i, j = 1, 2, . . . , n),
**Output:** A square reciprocal matrix C = (cij) for (i, j = 1, 2, . . . , n);
1: for i = 1; i < n; i ++ do
2: for j = i ; j < n; j ++ do
3: cij = sqrt(tij /tji );
4: cji = 1/cij ;
5: end for
6: end for
I have the following matrix T:
T=[...
0.08 0.02 0.34 0.67;...
0.01 0.08 0.17 0.34;...
0.02 0.04 0.09 0.18;...
0.01 0.02 0.04 0.09]
The answer C I found on a paper is:
C = [...
1 2 4 8;...
0.50 1 2 4;...
0.25 0.50 1 2;...
0.13 0.25 0.50 1]
So far, I have tried the following code, but I am not certain about it. I couldn't find the exact answer C above. Any idea or help, please?
C=zeros(n,n);
for i = 1:n
for j = i:n
C(i,j) = sqrt(T(i,j)/T(j,i));
C(j,i) = 1/C(i,j) ;
end
end
C;

intersection of interpolated line and an interpolated curve matlab

I have astraightline with the following data
xinter=[1.13 1.36 1.62 1.81 2.00 2.30 2.61 2.83 3.05 3.39]
yinter=[0.10 0.25 0.40 0.50 0.60 0.75 0.90 1.00 1.10 1.25]
and I want to find the intersection with a result of an interpolated data
of a curve such as below
a50= [0.77 0.73 0.77 0.85 0.91 0.97 1.05 1.23 1.43 1.53 1.62 1.71 1.89 2.12 2.42];
a25= [0.51 0.60 0.70 0.80 0.85 0.90 0.96 1.09 1.23 1.30 1.36 1.41 1.53 1.67];
vel25=[0.43 0.35 0.30 0.27 0.25 0.24 0.22 0.21 0.22 0.24 0.25 0.27 0.30 0.35];
vel50=[0.68 0.57 0.49 0.43 0.40 0.38 0.36 0.34 0.36 0.38 0.40 0.43 0.49 0.57 0.68 ];
% back up original data, just for final plot
bkp_a50 = a50 ; bkp_vel50 = vel50 ;
% make second x vector monotonic
istart = find( diff(a50)>0 , 1 , 'first') ;
a50(1:istart-1) = [] ;
vel50(1:istart-1) = [] ;
% prepare a 3rd dimension vector (from 25 to 50)
T = [repmat(25,size(a25)) ; repmat(40,size(a50)) ] ;
% merge all observations together
A = [ a25 ; a50] ;
V = [vel25 ; vel50] ;
% find the minimum domain on which data can be interpolated
% (anything outside of that will return NaN)
Astart = max( [min(a25) min(a50)] ) ;
Astop = min( [max(a25) max(a50)] ) ;
% use the function 'griddata'
[TI,AI] = meshgrid( 25:40 , linspace(Astart,Astop,10) ) ;
VI = griddata(T,A,V,TI,AI) ;
% plot all the intermediate curves
%plot(AI,VI)
hold on
% the original curves
%plot(a25,vel25,'--k','linewidth',2)
%plot(bkp_a50,bkp_vel50,'--k','linewidth',2)
% Highlight the curve at T = 30 ;
c30 = find( TI(1,:) == 40 ) ;
plot(AI(:,c30),VI(:,c30),'--r','linewidth',2)
xinter=[1.13 1.36 1.62 1.81 2.00 2.30 2.61 2.83 3.05 3.39]
yinter=[0.10 0.25 0.40 0.50 0.60 0.75 0.90 1.00 1.10 1.25]
x1inter=(AI(:,c30))';
y1inter=(VI(:,c30))';
yy2 = interp1(xinter, yinter, x1inter,'spline')
plot(xinter,yinter, '--k','linewidth',2)
idx = find((y1inter - yy2) < eps, 1); %// Index of coordinate in array
px = x1inter(idx)
py = y1inter(idx)
plot(px, py, 'ro', 'MarkerSize', 18)
But there is an error in the result when I modify x1inter
You can use piecewise polynomial curvefitting and the fzero function to find the intersection point:
pp1 = pchip(xinter,yinter); % Curve 1
pp2 = pchip(AI(:,c30),VI(:,c30)); % Curve 2
fun = #(x) ppval(pp1,x) - ppval(pp2,x); % Curve to evaluate
xzero = fzero(fun,mean(xinter)) % intersection x value
yzero = ppval(pp1,xzero)
plot(xzero, yzero, 'bo', 'MarkerSize', 18)

how can transform a matrix matlab into file .txt?

I have a matrix proba (size :10 * 5).
proba=[0.5 0.3 0.8 0.9 0.8;
0.50 0.36 0.58 0.58 0.98;
0.1 0.25 0.6 0.8 0.9;
0.5 0.3 0.8 0.9 0.8;
0.2 0.9 0.58 0.58 0.69;
0.58 0.14 0.1 0.2 0.3;
0.25 0.9 0.8 0.7 0.5;
0.58 0.69 0.25 0.1 0.1;
0.1 0.25 0.36 0.2 0.3;
0.5 0.3 0.8 0.9 0.8 ];
I want to transform this matrix into a text file (proba.txt) with which the index column is written and the value of the column for each line as follows :
1 0.5 2 0.3 3 0.8 4 0.9 5 0.8
1 0.50 2 0.36 3 0.58 4 0.58 5 0.98
.
.
.
1 0.5 2 0.3 3 0.8 4 0.9 5 0.8
Please I need help, how can I do it?thanks in advance
You can use this function, it is useful for every matrix.
function data = addIndex(X)
[r, c] = size(X);
index = ones(r, 1);
data = zeros(r, 2 * c);
for i = 1:c
data(:, 2 * i - 1) = i .* index;
data(:, 2 * i) = X(:, i);
end
dlmwrite('proba.txt', data, '\t')
end
you can easily do this using dlmwrite, but first you want to add the column of indexes in front of your matrix:
function result = writematrix(proba)
rowind = 1:size(proba,2);
for t = 1:size(proba,1);
C(t,:,:) = [rowind',proba(t,:)']';
D(t,:) = C(t(:),:);
end
dlmwrite('filename.txt',D,'\t') %//I assume you want tab delimiter, if you want space, it is ' ' instead
%//dlmwrite('filename.txt',D,' ')
end
Note that this will write the text file into your local directory, and that it only works for numerical values, not strings, for strings, it is better to use csvwrite.
EDIT : Ops, didn't read the question fully, this should now work fine.

How to specify a range and perform a function accordingly in matlab?

I need to perform the following function in matlab.
I had tried the following code but somehow my if statement is wrong. I'd like to know how to use the if statement efficiently here. If there is any other method in which i could perform the function please do help. My code is as follows
if (y(i,j) < -0.5, y(i,j) >= -1)
f(i,j) = 0
elseif (y(i,j) < 0, y(i,j) >= -0.5)
f(i,j) = 1
elseif (y(i,j) < 0.75, y(i,j) >= 0)
f(i,j) = 2
elseif (y(i,j) < 1, y(i,j) >= 0.75)
f(i,j) = 3
end
Here y(i,j) is a 1 x 256 matrix. Thanks
You need to use the logical AND operator to tie two Boolean expressions together. You are using a comma which is not correct:
if (y(i,j) < -0.5 && y(i,j) >= -1)
f(i,j) = 0
elseif (y(i,j) < 0 && y(i,j) >= -0.5)
f(i,j) = 1
elseif (y(i,j) < 0.75 && y(i,j) >= 0)
f(i,j) = 2
elseif (y(i,j) < 1 && y(i,j) >= 0.75)
f(i,j) = 3
end
However, it looks like you're using this in a for loop and I wouldn't perform the above in a loop. Use logical indexing instead:
f(y < -0.5 & y >= 1) = 0;
f(y < 0 & y >= -0.5) = 1;
f(y < 0.75 & y >= 0) = 2;
f(y < 1 & y >= 0.75) = 3;
This is assuming that f is the same size as y.

MATLAB Figure file

I have a problem with contour figure, when I run my syntax I get error like:
Error using contourf (line 66)
Z must be size 2x2 or greater.
Error in example (line 660)
contourf (x,y,c); colorbar;
and this is my syntax:
%---------------------stack1--------------------------------------------
v = 0.5; % velocity
lambda = 0; % decay rate
Q = 1; % emission rate(s)
u = 3; % wind speed
P = 1; % Ambient Pressure
D = 6; % inside diameter
V = 22.4; % volumetric flow rate of stack gas
Ts = 400; % temperature of stack gas
Ta = 283; % temperature of ambient air
xstack = 0; ystack = 60; % stack location(s)
xmin = 0.5; xmax = 3.5; % x-axis interval
ymin = 0; ymax = 100; % y-axis interval (used only for d>1))
h = 50; % physical stack height
z = 0; % height of observation (=0 for ground surface)
gplot = 1; % plot option (=1 yes; =0 no)
gcont = 2; % contour plot option (=2 filled; =1 yes; =0 none)
%----------------------------------execution-------------------------------
[x,y] = meshgrid (linspace(xmin,xmax,100),linspace(ymin,ymax,100));
c = zeros (size(x)); e = ones(size(x));
Dy = linspace(1,100,100); % in meters
Dz = Dy'; % in meters
[Dy,Dz] = meshgrid(Dz,Dy);
for i=1:100
for j=1:100
%...Pasquill-gifford for Dy
c = 24.167; d = 2.5334;%...Pasquill Stability Category is A
if x(i,j)<0.10; % x in kilometers
th = 0.017453293.*(c - d.*log(x(i,j)));
Dy(i,j) = 465.11628.*x(i,j).*(tan(th));
end
c = 18.3330; d = 1.8096;%...Pasquill Stability Category is B
if x(i,j)<0.20 % x in kilometers
th = 0.017453293.*(c - d.*log(x(i,j)));
Dy(i,j) = 465.11628.*x(i,j).*(tan(th));
end
c = 12.5000; d = 1.0857;%...Pasquill Stability Category is C
if x(i,j) == 4; % x in kilometers
th = 0.017453293.*(c - d.*log(x(i,j)));
Dy(i,j) = 465.11628.*x(i,j).*(tan(th));
end
c = 8.3330; d = 0.72382;%...Pasquill Stability Category is D
if x(i,j)== 0.30 % x in kilometers
th = 0.017453293.*(c - d.*log(x(i,j)));
Dy(i,j) = 465.11628.*x(i,j).*(tan(th));
end
c = 6.2500; d = 0.54287; %...Pasquill Stability Category is E
if x(i,j) < 0.10 % x in kilometers
th = 0.017453293.*(c - d.*log(x(i,j)));
Dy(i,j) = 465.11628.*x(i,j).*(tan(th));
end
c = 4.1667; d = 0.36191; %...Pasquill Stability Category is F
if x(i,j) < 0.20 % x in kilometers
th = 0.017453293.*(c - d.*log(x(i,j)));
Dy(i,j) = 465.11628.*x(i,j).*(tan(th));
end
%...Pasquill-gifford for Dz
if x(i,j)<0.10 % x in kilometers
a = 122.8; b = 0.9447;%...stabilitas is A
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.100 <= x(i,j) && x(i,j) < 0.150
a = 158.08; b = 1.0542;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.150 <= x(i,j) && x(i,j) < 0.200
a= 170.22 ; b= 1.0932 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.200 <= x(i,j) && x(i,j) < 0.250
a= 179.52 ; b= 1.1262 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.250 <= x(i,j) && x(i,j) < 0.300
a= 217.41 ; b= 1.2644 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.300 <= x(i,j) && x(i,j) < 0.400
a= 258.89 ; b= 1.4094 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.400 <= x(i,j) && x(i,j) < 0.500
a= 346.75 ; b= 1.7283 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.500 <= x(i,j) && x(i,j) < 3.110
a= 453.85 ; b= 2.1166 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif x(i,j) >= 3.110
a= 453.85 ; b= 2.1166 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
if x(i,j)<0.20 % x in kilometers
a = 90.673; b = 0.93198;%...stabilitas is B
Dz(i,j)= a.*x(i,j).^b;
end
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.21 <= x(i,j) && x(i,j) < 0.40
a = 98.483; b = 0.98332;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz = 5000;
end
elseif x(i,j)>= 0.40
a = 109.400; b = 1.09710;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz = 5000;
end
if x(i,j) == all % x in kilometers
a = 61.141; b = 0.91465;%...stabilitas is C
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz = 5000;
end
if x(i,j)== 0.30 % x in kilometers
a = 34.459; b = 0.86974;%...stabilitas is D
Dz(i,j)= a.*x(i,j).^b;
end
if 0.31 <= x(i,j) && x(i,j) < 1.00
a = 32.093; b = 0.81066;
Dz(i,j)= a.*x(i,j).^b;
end
if 1.01 <= x(i,j) && x(i,j) < 3.00
a = 32.093; b = 0.64403;
Dz(i,j)= a.*x(i,j).^b;
end
if 3.01 <= x(i,j) && x(i,j) < 10.00
a = 33.504; b = 0.60486;
Dz(i,j)= a.*x(i,j).^b;
end
if 10.01 <= x(i,j) && x(i,j) < 30.00
a = 36.650; b = 0.56589;
Dz(i,j)= a.*x(i,j).^b;
end
if x(i,j)>= 30.00
a = 44.053; b =0.51179;
Dz(i,j)= a.*x(i,j).^b;
end
if x(i,j) < 0.10 % x in kilometers
a = 24.260; b = 0.83660; %...stabilitas is E
Dz(i,j)= a.*x(i,j).^b;
end
if 0.10 <= x(i,j) && x(i,j) < 30.00
a = 23.331; b = 0.81956;
Dz(i,j)= a.*x(i,j).^b;
end
if 0.31 <= x(i,j) && x(i,j) < 1.00
a = 21.628; b = 0.75660;
Dz(i,j)= a.*x(i,j).^b;
end
if 1.01 <= x(i,j) && x(i,j) < 2.00
a = 21.628; b = 0.63077;
Dz(i,j)= a.*x(i,j).^b;
end
if 2.01 <= x(i,j) && x(i,j) < 4.00
a = 22.534; b = 0.57154;
Dz(i,j)= a.*x(i,j).^b;
end
if 4.01 <= x(i,j) && x(i,j) < 10.00
a = 24.703; b = 0.50527;
Dz(i,j)= a.*x(i,j).^b;
end
if 10.01 <= x(i,j) && x(i,j) < 20.00
a = 26.970; b = 0.46713;
Dz(i,j)= a.*x(i,j).^b;
end
if 20.01 <= x(i,j) && x(i,j) < 40.00
a = 35.420; b = 0.37615;
Dz(i,j)= a.*x(i,j).^b;
end
if x(i,j) >=40.00
a = 44.053; b = 0.51179;
Dz(i,j)= a.*x(i,j).^b;
end
if x(i,j) < 0.20 % x in kilometers
a = 15.209; b = 0.81558;%...stabilitas is F
Dz(i,j)= a.*x(i,j).^b;
end
if 0.21 <= x(i,j) && x(i,j) < 0.70
a = 14.457; b = 0.78407;
Dz(i,j)= a.*x(i,j).^b;
end
if 0.71 <= x(i,j) && x(i,j) < 1.00
a = 13.953; b = 0.68465;
Dz(i,j)= a.*x(i,j).^b;
end
if 1.01 <= x(i,j) && x(i,j) < 2.00
a = 13.953; b = 0.63227;
Dz(i,j)= a.*x(i,j).^b;
end
if 2.01 <= x(i,j) && x(i,j) < 3.00
a = 14.823; b = 0.54503;
Dz(i,j)= a.*x(i,j).^b;
end
if 3.01 <= x(i,j) && x(i,j) < 7.00
a = 16.187; b = 0.46490;
Dz(i,j)= a.*x(i,j).^b;
end
if 7.01 <= x(i,j) && x(i,j) < 15.00
a = 17.836; b = 0.41507;
Dz(i,j)= a.*x(i,j).^b;
end
if 15.01 <= x(i,j) && x(i,j) < 30.00
a = 22.651; b = 0.32681;
Dz(i,j)= a.*x(i,j).^b;
end
if 30.01 <= x(i,j) && x(i,j) < 60.00
a = 27.074; b = 0.27436;
Dz(i,j)= a.*x(i,j).^b;
end
if x(i,j)>= 60.00
a = 34.219; b = 0.21716;
Dz(i,j)= a.*x(i,j).^b;
end
end
end
end
end
for i = 1:size(Q,2)
xx = x - xstack(i);
yy = y - ystack(i);
end
deltah(i,j) = V.*D./u.*1.5 + 2.68.*(10^(-3)).*P.*(Ts-Ta).*D./Ts;
H = h + deltah;
c1 = c + Q(i).*e./(4.*pi.*xx.*sqrt(Dy.*Dz)).*exp(-v.*yy.*yy./(4.*Dy.*xx)).*...
(exp(-v.*(z-H(i)).*(z-H(i)).*e./(4.*Dz.*xx))+exp(-v.*(z+H(i)).*(z+H(i)).*e./(4.*Dz.*xx)))...
.*exp(-lambda.*xx./v);
%--------------------------stack2---------------------------------------------
v = 0.5; % velocity
lambda = 0; % decay rate
Q = 1; % emission rate(s)
u = 3; % wind speed
P = 1; % Ambient Pressure
D = 6; % inside diameter
V = 22.4; % volumetric flow rate of stack gas
Ts = 400; % temperature of stack gas
Ta = 283; % temperature of ambient air
xstack = 0; ystack = 40; % stack location(s)
xmin = 0.5; xmax = 3.5; % x-axis interval
ymin = 0; ymax = 100; % y-axis interval (used only for d>1))
h = 50; % physical stack height
z = 0; % height of observation (=0 for ground surface)
gplot = 1; % plot option (=1 yes; =0 no)
gcont = 2; % contour plot option (=2 filled; =1 yes; =0 none)
%----------------------------------execution-------------------------------
[x,y] = meshgrid (linspace(xmin,xmax,100),linspace(ymin,ymax,100));
c = zeros (size(x)); e = ones(size(x));
Dy = linspace(1,100,100); % in meters
Dz = Dy'; % in meters
[Dy,Dz] = meshgrid(Dz,Dy);
for i=1:100
for j=1:100
%...Pasquill-gifford for Dy
c = 24.167; d = 2.5334;%...Pasquill Stability Category is A
if x(i,j)<0.10; % x in kilometers
th = 0.017453293.*(c - d.*log(x(i,j)));
Dy(i,j) = 465.11628.*x(i,j).*(tan(th));
end
c = 18.3330; d = 1.8096;%...Pasquill Stability Category is B
if x(i,j)<0.20 % x in kilometers
th = 0.017453293.*(c - d.*log(x(i,j)));
Dy(i,j) = 465.11628.*x(i,j).*(tan(th));
end
c = 12.5000; d = 1.0857;%...Pasquill Stability Category is C
if x(i,j) == 4; % x in kilometers
th = 0.017453293.*(c - d.*log(x(i,j)));
Dy(i,j) = 465.11628.*x(i,j).*(tan(th));
end
c = 8.3330; d = 0.72382;%...Pasquill Stability Category is D
if x(i,j)== 0.30 % x in kilometers
th = 0.017453293.*(c - d.*log(x(i,j)));
Dy(i,j) = 465.11628.*x(i,j).*(tan(th));
end
c = 6.2500; d = 0.54287; %...Pasquill Stability Category is E
if x(i,j) < 0.10 % x in kilometers
th = 0.017453293.*(c - d.*log(x(i,j)));
Dy(i,j) = 465.11628.*x(i,j).*(tan(th));
end
c = 4.1667; d = 0.36191; %...Pasquill Stability Category is F
if x(i,j) < 0.20 % x in kilometers
th = 0.017453293.*(c - d.*log(x(i,j)));
Dy(i,j) = 465.11628.*x(i,j).*(tan(th));
end
%...Pasquill-gifford for Dz
if x(i,j)<0.10 % x in kilometers
a = 122.8; b = 0.9447;%...stabilitas is A
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.100 <= x(i,j) && x(i,j) < 0.150
a = 158.08; b = 1.0542;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.150 <= x(i,j) && x(i,j) < 0.200
a= 170.22 ; b= 1.0932 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.200 <= x(i,j) && x(i,j) < 0.250
a= 179.52 ; b= 1.1262 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.250 <= x(i,j) && x(i,j) < 0.300
a= 217.41 ; b= 1.2644 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.300 <= x(i,j) && x(i,j) < 0.400
a= 258.89 ; b= 1.4094 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.400 <= x(i,j) && x(i,j) < 0.500
a= 346.75 ; b= 1.7283 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.500 <= x(i,j) && x(i,j) < 3.110
a= 453.85 ; b= 2.1166 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif x(i,j) >= 3.110
a= 453.85 ; b= 2.1166 ;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz(i,j)=5000;
end
if x(i,j)<0.20 % x in kilometers
a = 90.673; b = 0.93198;%...stabilitas is B
Dz(i,j)= a.*x(i,j).^b;
end
if Dz(i,j)>5000
Dz(i,j)=5000;
end
elseif 0.21 <= x(i,j) && x(i,j) < 0.40
a = 98.483; b = 0.98332;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz = 5000;
end
elseif x(i,j)>= 0.40
a = 109.400; b = 1.09710;
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz = 5000;
end
if x(i,j) == all % x in kilometers
a = 61.141; b = 0.91465;%...stabilitas is C
Dz(i,j)= a.*x(i,j).^b;
if Dz(i,j)>5000
Dz = 5000;
end
if x(i,j)== 0.30 % x in kilometers
a = 34.459; b = 0.86974;%...stabilitas is D
Dz(i,j)= a.*x(i,j).^b;
end
if 0.31 <= x(i,j) && x(i,j) < 1.00
a = 32.093; b = 0.81066;
Dz(i,j)= a.*x(i,j).^b;
end
if 1.01 <= x(i,j) && x(i,j) < 3.00
a = 32.093; b = 0.64403;
Dz(i,j)= a.*x(i,j).^b;
end
if 3.01 <= x(i,j) && x(i,j) < 10.00
a = 33.504; b = 0.60486;
Dz(i,j)= a.*x(i,j).^b;
end
if 10.01 <= x(i,j) && x(i,j) < 30.00
a = 36.650; b = 0.56589;
Dz(i,j)= a.*x(i,j).^b;
end
if x(i,j)>= 30.00
a = 44.053; b =0.51179;
Dz(i,j)= a.*x(i,j).^b;
end
if x(i,j) < 0.10 % x in kilometers
a = 24.260; b = 0.83660; %...stabilitas is E
Dz(i,j)= a.*x(i,j).^b;
end
if 0.10 <= x(i,j) && x(i,j) < 30.00
a = 23.331; b = 0.81956;
Dz(i,j)= a.*x(i,j).^b;
end
if 0.31 <= x(i,j) && x(i,j) < 1.00
a = 21.628; b = 0.75660;
Dz(i,j)= a.*x(i,j).^b;
end
if 1.01 <= x(i,j) && x(i,j) < 2.00
a = 21.628; b = 0.63077;
Dz(i,j)= a.*x(i,j).^b;
end
if 2.01 <= x(i,j) && x(i,j) < 4.00
a = 22.534; b = 0.57154;
Dz(i,j)= a.*x(i,j).^b;
end
if 4.01 <= x(i,j) && x(i,j) < 10.00
a = 24.703; b = 0.50527;
Dz(i,j)= a.*x(i,j).^b;
end
if 10.01 <= x(i,j) && x(i,j) < 20.00
a = 26.970; b = 0.46713;
Dz(i,j)= a.*x(i,j).^b;
end
if 20.01 <= x(i,j) && x(i,j) < 40.00
a = 35.420; b = 0.37615;
Dz(i,j)= a.*x(i,j).^b;
end
if x(i,j) >=40.00
a = 44.053; b = 0.51179;
Dz(i,j)= a.*x(i,j).^b;
end
if x(i,j) < 0.20 % x in kilometers
a = 15.209; b = 0.81558;%...stabilitas is F
Dz(i,j)= a.*x(i,j).^b;
end
if 0.21 <= x(i,j) && x(i,j) < 0.70
a = 14.457; b = 0.78407;
Dz(i,j)= a.*x(i,j).^b;
end
if 0.71 <= x(i,j) && x(i,j) < 1.00
a = 13.953; b = 0.68465;
Dz(i,j)= a.*x(i,j).^b;
end
if 1.01 <= x(i,j) && x(i,j) < 2.00
a = 13.953; b = 0.63227;
Dz(i,j)= a.*x(i,j).^b;
end
if 2.01 <= x(i,j) && x(i,j) < 3.00
a = 14.823; b = 0.54503;
Dz(i,j)= a.*x(i,j).^b;
end
if 3.01 <= x(i,j) && x(i,j) < 7.00
a = 16.187; b = 0.46490;
Dz(i,j)= a.*x(i,j).^b;
end
if 7.01 <= x(i,j) && x(i,j) < 15.00
a = 17.836; b = 0.41507;
Dz(i,j)= a.*x(i,j).^b;
end
if 15.01 <= x(i,j) && x(i,j) < 30.00
a = 22.651; b = 0.32681;
Dz(i,j)= a.*x(i,j).^b;
end
if 30.01 <= x(i,j) && x(i,j) < 60.00
a = 27.074; b = 0.27436;
Dz(i,j)= a.*x(i,j).^b;
end
if x(i,j)>= 60.00
a = 34.219; b = 0.21716;
Dz(i,j)= a.*x(i,j).^b;
end
end
end
end
end
for i = 1:size(Q,2)
xx = x - xstack(i);
yy = y - ystack(i);
end
deltah(i,j) = V.*D./u.*1.5 + 2.68.*(10^(-3)).*P.*(Ts-Ta).*D./Ts;
H = h + deltah;
c2 = c + Q(i).*e./(4.*pi.*xx.*sqrt(Dy.*Dz)).*exp(-v.*yy.*yy./(4.*Dy.*xx)).*...
(exp(-v.*(z-H(i)).*(z-H(i)).*e./(4.*Dz.*xx))+exp(-v.*(z+H(i)).*(z+H(i)).*e./(4.*Dz.*xx)))...
.*exp(-lambda.*xx./v);
%----------------------------------output----------------------------------
if gplot
for i = 10:10:100
plot (c1(:,i)); hold on;
plot (c2(:,i)); hold on;
end
end
if gcont
figure;
if gcont > 1
contourf (x,y,c); colorbar;
else
contour (x,y,c);
end
end
Anyone can help me please?!
When I run the code you have posted, I find that the 'c' variable is a single value, while 'x' and 'y' are matrices. So your problem is in the dimensions of the variables you try to plot together.
To debug your code try inserting a breakpoint in the code where the error occurs. Then when you run the code, it will stop at the breakpoint and you can check the values and dimensions of your variables.