4D plot matlab gives error
5 ビュー (過去 30 日間)
古いコメントを表示
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);
0 件のコメント
回答 (1 件)
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
[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);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Lighting, Transparency, and Shading についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!