how to draw contour plot

4 次查看(过去 30 天)
mallela ankamma rao
good evening sir
sir i have to draw contour plot . i am taking some examples from other papers i am trying to find contour plot but i did not get results sir. please tell me where i had made mistake
the code is
% R0 = x*(1-b)*(1-v)*(u+y+p+t+w)*e/(u*(u+w)*(u+y+p+t))
% b =1.10340
% v =1.03330
% u =0.72936
% p =0.65722
% t =3.04270
% w =0.327688
% e =0.521749
% by substituting all values i got function Ro = x.*(0.00230).*((y+4.7569)/(y+4.442929))
x = linspace(0,0.02,1)
y = linspace(0,0.02,0.04)
[xm,ym] = meshgrid(x,y)
R0 = xm.*(0.00230).*((ym+4.7569)/(ym+4.442929))
contourf(xm,ym,R0)
colorbar
but original figure from other paper is
here alpha c is x and delta is y
i request you sir please help how to get this graph sir
thank you sir
  1 个评论
Adam Danz
Adam Danz 2022-4-22
Moving my answer here since there were two additional, excellent answers submitted at the same time.
These 2 lines aren't doing what you think they are doing. Check out the documentation for linspace.
x = linspace(0,0.02,1)
x = 0.0200
y = linspace(0,0.02,0.04)
y = 1×0 empty double row vector
Perhaps what you want is this, below, but it produces the a similar plot to the one in your question. Nevertheless, it's the correct plot given the data. If these results are unexpected, then the calculations in R0 are incorrect and we can't fix that because we don't know what they are supposed to be.
x = 0 : 0.02 : 1
x = 1×51
0 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.2000 0.2200 0.2400 0.2600 0.2800 0.3000 0.3200 0.3400 0.3600 0.3800 0.4000 0.4200 0.4400 0.4600 0.4800 0.5000 0.5200 0.5400 0.5600 0.5800
y = 0 : 0.02 : 0.04
y = 1×3
0 0.0200 0.0400
R0 = 0.00230*x(:).*((y+4.7569)./(y+4.442929))
R0 = 51×3
1.0e+00 * 0 0 0 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0004 0.0004 0.0004 0.0004 0.0004 0.0004
contourf(x,y,R0')
colorbar

请先登录,再进行评论。

回答(3 个)

Davide Masiello
Davide Masiello 2022-4-22
编辑:Davide Masiello 2022-4-22
The problem was in your use of linspace
x = linspace(0,0.05,100);
y = linspace(0,1,100);
[xm,ym] = meshgrid(x,y);
R0 = xm.*(0.00230).*((ym+4.7569)./(ym+4.442929));
contourf(xm,ym,R0)
colorbar
  2 个评论
mallela ankamma rao
thanks alot for answering question sir
by applying same procedure to another equation i got same error sir
code:
x = linspace(0,0.02,100);
y = linspace(0,0.04,100);
[xm,ym] = meshgrid(x,y);
R0 = xm.*(1.31855-1.1109.*ym)/(0.029325+ym);
contourf(xm,ym,R0)
colorbar
image is
please resolve this problem also sir
sir may i know how do i take linspace because i got confused in this linspace sir
mallela ankamma rao
thanks alot sir i got it
x = linspace(0,0.02,100);
y = linspace(0,0.04,100);
[xm,ym] = meshgrid(x,y);
R0 = xm.*(1.31855-1.1109.*ym)./(0.029325+ym);
contourf(xm,ym,R0)
colorbar
sir please tell me how to take values on the graph like below graph

请先登录,再进行评论。


Voss
Voss 2022-4-22
There are a couple of problems.
First is the use of linspace. The arguments to linspace are (min value, max value, number of points), not (min value, spacing, max value), which is how the colon operator works.
Second is that you should use element-wise division ./ rather than matrix division / in your calculation of R0.
% x = linspace(0,0.02,1);
x = linspace(0,1,51);
% y = linspace(0,0.02,0.04);
y = linspace(0,0.04,3);
[xm,ym] = meshgrid(x,y);
% R0 = xm.*(0.00230).*((ym+4.7569)/(ym+4.442929))
R0 = xm.*(0.00230).*((ym+4.7569)./(ym+4.442929));
contourf(xm,ym,R0)
colorbar
(Also, judging by the picture you attached, you may need to rethink which variables are which in your code, since delta goes from 0 to 1 and alpha_c goes from 0 to ~0.05 in the picture.)

Steven Lord
Steven Lord 2022-4-22
There are a couple potential problems here. Did you really mean to make x a 1-element vector or did you mean to go from 0 to 1 in steps of 0.02? In the latter case use the colon operator :.
x = linspace(0,0.02,1) % Original
x = 0.0200
x_original = x; % Store for later use
x = 0:0.02:1 % I added this
x = 1×51
0 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.2000 0.2200 0.2400 0.2600 0.2800 0.3000 0.3200 0.3400 0.3600 0.3800 0.4000 0.4200 0.4400 0.4600 0.4800 0.5000 0.5200 0.5400 0.5600 0.5800
Similarly for y did you mean you wanted a vector with 0.04 elements between 0 and 0.02 or did you want 0.02 to be the spacing?
y = linspace(0,0.02,0.04) % Original
y = 1×0 empty double row vector
y_original = y; % Store for later use
y = 0:0.02:0.04 % I added this
y = 1×3
0 0.0200 0.0400
With your original x and y, xm and ym were empty and therefore so was R0. With the updated x and y they aren't empty.
[xm_original, ym_original] = meshgrid(x_original, y_original)
xm_original = [] ym_original = []
[xm,ym] = meshgrid(x,y)
xm = 3×51
0 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.2000 0.2200 0.2400 0.2600 0.2800 0.3000 0.3200 0.3400 0.3600 0.3800 0.4000 0.4200 0.4400 0.4600 0.4800 0.5000 0.5200 0.5400 0.5600 0.5800 0 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.2000 0.2200 0.2400 0.2600 0.2800 0.3000 0.3200 0.3400 0.3600 0.3800 0.4000 0.4200 0.4400 0.4600 0.4800 0.5000 0.5200 0.5400 0.5600 0.5800 0 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.2000 0.2200 0.2400 0.2600 0.2800 0.3000 0.3200 0.3400 0.3600 0.3800 0.4000 0.4200 0.4400 0.4600 0.4800 0.5000 0.5200 0.5400 0.5600 0.5800
ym = 3×51
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400
You probably want to use element-wise division instead of matrix division in your calculation of R0. Here's your original R0 code operating on your original xm and ym variables.
R0_original = xm_original.*(0.00230).*((ym_original+4.7569)/(ym_original+4.442929))
R0_original = []
With the updated xm and ym and using element-wise division the new R0 is not empty.
R0_element = xm.*(0.00230).*((ym+4.7569)./(ym+4.442929));
size(R0_element)
ans = 1×2
3 51
Let's visualize the two R0 arrays. Since R0_original is empty the first surface plot is pretty boring.
figure
surf(xm_original, ym_original, R0_original);
title('R0\_original with matrix division')
The one for R0_element isn't so boring.
figure
surf(xm, ym, R0_element);
title('R0\_element with element-wise division')
Now let's look at the contour plot. You're probably going to want to specify the contour levels of your choice.
figure
contourf(xm, ym, R0_element)

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by