4D plot matlab gives error

2 Ansichten (letzte 30 Tage)
Lotte van Dijk
Lotte van Dijk am 28 Jul. 2023
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);

Antworten (1)

Nathan Hardenberg
Nathan Hardenberg am 28 Jul. 2023
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);

Kategorien

Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by