4D plot matlab gives error

조회 수: 3 (최근 30일)
Lotte van Dijk
Lotte van Dijk 2023년 7월 28일
답변: Nathan Hardenberg 2023년 7월 28일
This is my code:
I want a density/surface plot with the x,y and angle on the x,y and z axis and Pc is given by the color bar. but with this code I get the following error:
Error using surf
Z must be a matrix, not a scalar or vector.
Error in Small_plots (line 9)
surf(X, Y, angle, Pc, 'EdgeColor', 'interp');
how can i fix this?
[X,Y] = meshgrid(50:3.8462:400,30:0.3297:60);
gamma = 72.2 * 10^-3;
angle = (30:0.3297:60);
dynamic_viscosity = 1.003 * 10^-3;
Pc = abs(((2 .* cosd(angle))./(X .* 10^-6) + ((cosd(angle) + cosd(angle))./(Y .* 10^-6))).*gamma) ./ 1000;
figure;
surf(X, Y, angle, Pc, 'EdgeColor', 'interp');
xlabel('Channel width [um]', 'FontSize', 12);
ylabel('Channel height [um]', 'FontSize', 12);
zlabel('Angle', 'FontSize', 12);
cb = colorbar;
cb.Label.String = 'Capillary pressure [kPa]';
title('Influence of channel height and width on capillary pressure', 'FontSize', 16);

답변 (1개)

Nathan Hardenberg
Nathan Hardenberg 2023년 7월 28일
The error-message is pretty precise. If you want to plot a surface you need a z-hight for every (x,y) position. Thats why it needs to be a 2D matrix.
If I understand correctly, you want to calculate the capillary pressure with regards to width, height and angle:
This does not result in a surface, but rather in a volume. You should take a look in this documentation about visualizing 4D-Data: https://ch.mathworks.com/help/matlab/visualize/visualizing-four-dimensional-data.html
I would recommend to use a slice() plot and define planes you are interested in.
[X, Y, angle] = meshgrid(50:3.8462:400,30:0.3297:60, 30:0.3297:60); % 3D-meshgrid
gamma = 72.2 * 10^-3;
dynamic_viscosity = 1.003 * 10^-3;
Pc = abs(((2 .* cosd(angle))./(X .* 10^-6) + ((cosd(angle) + cosd(angle))./(Y .* 10^-6))).*gamma) ./ 1000;
figure;
xslice = [50 200]; yslice = 45; zslice = [31 45]; % define the cross sections to view
slice(X, Y, angle, Pc, xslice, yslice, zslice) % display the slices
shading interp % this removes the mesh/grid lines (also try removing this line)
xlabel('Channel width [µm]', 'FontSize', 10);
ylabel('Channel height [µm]', 'FontSize', 10);
zlabel('Angle', 'FontSize', 10);
cb = colorbar;
cb.Label.String = 'Capillary pressure [kPa]';
title('Influence of channel height and width on capillary pressure', 'FontSize', 10);

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by