Concentration variation in 3D surface plot

조회 수: 7 (최근 30일)
Mahima Horta
Mahima Horta 2024년 7월 9일
댓글: Mahima Horta 2024년 7월 9일
Hi all,
I am having many data points for concentration in 3D i.e., C @ (x,y,z). I would like to generate a concentration surface plot for the data. Can anyone please help?
Thanks in advance
Regards,
Mahima

채택된 답변

Garmit Pant
Garmit Pant 2024년 7월 9일
Hello Mahima
From what I gather, you have the concentration values stored in ‘C’ matrix and have the 3D coordinates of these values. You want to plot the surface plot to depict concentration variation.
The surface plot can be made using the “meshgrid” and “surface” MATLAB function. The following code snippet generates dummy data and plots it on a surface plot:
% Generate grid data
x = linspace(0, 10, 50); % X-coordinates
y = linspace(0, 10, 50); % Y-coordinates
[X, Y] = meshgrid(x, y);
% Define a function for Z-values (e.g., a Gaussian surface)
Z = 3 * exp(-((X - 5).^2 + (Y - 5).^2) / 10) + sin(X) + cos(Y);
% Define concentration values based on some function of X, Y, Z
concentration = Z .* 10 + rand(size(Z)) * 5; % Add some randomness for realism
% Plotting
figure;
surf(X, Y, Z, concentration, 'EdgeColor', 'none');
colorbar; % Adding color bar which maps values to colors
colormap('jet'); % Set colormap to jet
xlabel('X axis');
ylabel('Y axis');
zlabel('Z axis');
title('3D Concentration Surface Plot');
% Adjust view angle for better visualization
view(3);
For further understanding, refer to the following MathWorks Documentation:
  1. “meshgrid” function- https://www.mathworks.com/help/matlab/ref/meshgrid.html
  2. surf” function- https://www.mathworks.com/help/matlab/ref/surf.html
I hope you find the above explanation and suggestions useful!
  댓글 수: 1
Mahima Horta
Mahima Horta 2024년 7월 9일
Hi,
Thanks for the help! Much appreciated
However when I am using the same way for my problem there seems to be an issue. I do not have functions for Z and concentration. Please help, where am I wrong?
Regards,
Mahima
x = [1,5,6];
y = [2,4,8];
[X, Y] = meshgrid(x, y);
Z = [3,3,3];
concentration = [1, 3, 5];
% Plotting
figure;
surf(X, Y, Z, concentration,'EdgeColor', 'none');
Error using surf (line 71)
Z must be a matrix, not a scalar or vector.
colorbar; % Adding color bar which maps values to colors
colormap('jet'); % Set colormap to jet

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by