- contourf(Z,v) draws a filled contour plot of matrix Z with contour lines at the data values specified in the monotonically increasing vector v. To display a single contour line at a particular value, define v as a two-element vector with both elements equal to the desired contour level. For example, to draw a single contour of level k, use contourf(Z,[k k]). Specifying the vector v sets the LevelListMode property to manual.
What should I do in order to remove this weird HEAT GRADIENT (flow line) ?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Calin Pastean
am 23 Apr. 2015
Kommentiert: Star Strider
am 24 Apr. 2015
I am trying to plot the heat flow through a plate, but for some odd reason I am getting a weird flow line on the cold side (lower right corner). Could somebody check the code for me? I have added a screenshot of the plot I am getting.
Also, How could I add a "hole" in this plot? An area which cannot be affected by the heat flow.
%Predefined Variables
dx = 1;
dy = 1;
%Plate dimensions
plate_length = 64;
plate_height = 96;
%Heated & Cooled points
heated_length = 32;
heated_height = 32;
cooled_length = 16;
cooled_height = 16;
heated_temp = 100;
cooled_temp = -100;
%Grid
x = 0:dx:plate_length;
y = 0:dy:plate_height;
nx = length(x);
ny = length(y);
[x_arr, y_arr] = meshgrid(x,y);
temp=zeros(ny, nx);
%Heating & Cooling Points
heated_top = find((y_arr == plate_height) & (x_arr <= heated_length));
heated_left = find((y_arr >= plate_height-heated_height) & (x_arr == 0));
heated_points = union(heated_top, heated_left);
cooled_bottom = find((y_arr == 0) & (x_arr >= plate_length-cooled_length));
cooled_right = find((y_arr <= cooled_height) & (x_arr == plate_length));
cooled_points = union(cooled_bottom, cooled_right);
temp(heated_points) = heated_temp;
temp(cooled_points) = cooled_temp;
%Iteration
for k=1:1:30
inner_x = 2:nx-1;
inner_y = 2:ny-1;
x_diff = temp(inner_y, inner_x+1) + temp(inner_y, inner_x-1);
y_diff = temp(inner_y+1, inner_x) + temp(inner_y-1, inner_x);
old_inner = temp(inner_y, inner_x);
temp(inner_y, inner_x) = (x_diff +y_diff)/4;
%Plotting
contourf(x_arr,y_arr,temp);
%surf(x_arr,y_arr,temp);
%contour(x_arr,y_arr,temp);
%hold on;
drawnow;
end
0 Kommentare
Akzeptierte Antwort
Star Strider
am 24 Apr. 2015
you can specify the levels at which to draw the contours.
2 Kommentare
Star Strider
am 24 Apr. 2015
The ‘v’ vector has to be monotonically increasing, but it doesn’t have to be regularly-spaced. If you can determine the values of the contours at the top left and lower right, you can define ‘v’ to include only them.
You can also set the number of contours, so that would be my first option. I would then experiment with ‘v’ if defining the number of the contours didn’t work.
I understand sleep deprivation only too well. You have my sympathies!
On a completely different note, if you ever need to find the zeros of a bivariate function, setting ‘v’ to [0; 0] will plot them and produce the (x,y) values if you want them. You can get the (x,y) values for all the contours by asking for them with an output argument from contour and its friends.
Weitere Antworten (1)
Image Analyst
am 24 Apr. 2015
It seems to be just an artifact of where contour is drawing the lines. Why don't you use an image instead, like with imshow:
%Predefined Variables
dx = 1;
dy = 1;
%Plate dimensions
plate_length = 64;
plate_height = 96;
%Heated & Cooled points
heated_length = 32;
heated_height = 32;
cooled_length = 16;
cooled_height = 16;
heated_temp = 100;
cooled_temp = -100;
%Grid
x = 0:dx:plate_length;
y = 0:dy:plate_height;
nx = length(x);
ny = length(y);
[x_arr, y_arr] = meshgrid(x,y);
temp=zeros(ny, nx);
%Heating & Cooling Points
heated_top = find((y_arr == plate_height) & (x_arr <= heated_length));
heated_left = find((y_arr >= plate_height-heated_height) & (x_arr == 0));
heated_points = union(heated_top, heated_left);
cooled_bottom = find((y_arr == 0) & (x_arr >= plate_length-cooled_length));
cooled_right = find((y_arr <= cooled_height) & (x_arr == plate_length));
cooled_points = union(cooled_bottom, cooled_right);
temp(heated_points) = heated_temp;
temp(cooled_points) = cooled_temp;
inner_x = 2:nx-1;
inner_y = 2:ny-1;
%Iteration
for k=1:30
x_diff = temp(inner_y, inner_x+1) + temp(inner_y, inner_x-1);
y_diff = temp(inner_y+1, inner_x) + temp(inner_y-1, inner_x);
old_inner = temp(inner_y, inner_x);
temp(inner_y, inner_x) = (x_diff +y_diff)/4;
% Display temp image.
subplot(1,2,1);
imshow(temp, [], 'InitialMagnification', 800);
axis on;
axis image;
colormap(hot(256));
colorbar;
%Plotting
subplot(1,2,2);
contourf(x_arr,y_arr,temp);
drawnow;
end
3 Kommentare
Image Analyst
am 24 Apr. 2015
If you look at the actual data values of temp, you will see there is really no big change in values around that line - it's like 1e-8 and 0. It's purely an artifact of where it had to draw the line to get the required number of contour lines in there. You could try to change the number of contour lines if you didn't want to display it as an image and wanted to use contour instead. You can change the number of colors in hot() to make it more quantized if you want. Then the only difference will be that image won't have black lines separating the "level" or posterized regions of the image (contour draws black lines between the colors while imshow does not).
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!