Can't plot contour graph on a different plane

4 次查看(过去 30 天)
I plotted a contour graph on the x-y plane using this code with no problem:
figure(1)
iz = 1;
contourf(x_mesh(:,:,iz),y_mesh(:,:,iz),squeeze(g(:,:,iz)))
But once I tried to do it for the x-z plane, using this:
figure(2)
iy =1;
contourf(x_mesh(:,iy,:),y_mesh(:,iy,:),squeeze(g(:,iy,:)))
I got the following error:
"Error using contourf
Input arguments must have at most 2 dimensions."
Can anyone tell me why this is and how I can fix it? Here's the full code if it helps:
clear all
close all
clc
%Constant
rho = 4420; %kg/m^3
Cp = 550; %J/kg?K
T0 = 303.15; %K
A = 0.5; %[Absorbtivity]
k = 7.2; %W/m/K
alpha = 2.96*10^-6; %m^2/s
D = alpha;
P = 100; %W
v = 1; %m/s
u = v;
Tm = 1933; %K
d_laser = 0.0001; %m
r_laser = d_laser/2; %m
a = r_laser;
p = D/(u*a);
%Define
n = 100;
x = linspace(-0.00025,0.00125,n);
y = linspace(-0.00025,0.00025,n);
z = linspace(-0.00008,0.0005,n);
%Normalized
x_nor = x/a;
y_nor = y/a;
z_nor = z/(D*a/u).^0.5
[x_mesh,y_mesh,z_mesh] = ndgrid(x_nor,y_nor,z_nor);
fun = @(t) exp((-z_mesh.^2./(4*t))-((y_mesh.^2+(x_mesh-t).^2)./(4*p.*t+1)))./((4.*p.*t+1).*sqrt(t));
g = integral(fun,0,Inf,'ArrayValued',true);
figure(1)
hold on
iz = 1;
[C,h]= contourf(x_mesh(:,:,iz),y_mesh(:,:,iz),squeeze(g(:,:,iz)))
[C1,h1] = contour(x_mesh(:,:,iz),y_mesh(:,:,iz),squeeze(g(:,:,iz)),LevelList=0.16713,Color='red')
hold off
clabel(C,h,'manual','Color','white')
clabel(C1,h1,'manual','Color','white')
xticks(-5:5:25)
yticks(-5:2.5:5)
axis([-5 25 -5 5])
title('x\primey\prime plane')
xlabel('x\prime')
ylabel('y\prime')
colorbar
figure(2)
iy =1;
contourf(x_mesh(:,iy,:),y_mesh(:,iy,:),squeeze(g(:,iy,:)))
axis([-5 25 -10 0])
title('x\primez\prime plane')
xlabel('x\prime')
ylabel('z\prime')
colorbar

采纳的回答

Matt J
Matt J 2023-6-29
编辑:Matt J 2023-6-29
figure(2)
iy =1;
contourf(squeeze(x_mesh(:,iy,:)),squeeze(z_mesh(:,iy,:)),squeeze(g(:,iy,:)))
title('x^\prime z^\prime plane','Interpreter','tex')
xlabel('x^\prime','Interpreter','tex')
ylabel('z^\prime','Interpreter','tex')
colorbar

更多回答(0 个)

类别

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