how do i plot a coordinate field with values for each specified coordinate?
显示 更早的评论
the coordinate field:
y = 1:0.5:31;
x = -13:1:13;
[X,Y] = meshgrid (z,y);
But from here i have no clue which command to use to give each coordinate a value and plot with colormap afterwards.
I already have a .txt file with every value organized. So data (1,1) should become mesh (-13,1) and data (1,2) should be mesh (-12,1)
thanks in advance!
回答(1 个)
Soumya
2025-8-4
I understand that you have a coordinate field defined by some given ‘x’ and ‘y’ values, where each point on this grid should correspond to a value from a ‘.txt’ file. To solve this, you should load your ‘.txt’ file as a matrix, matching the grid size, then use MATLAB’s plotting functions such as ‘imagesc’ for a 2D heatmap, ‘surf’ for a 3D surface, or ‘contourf’ for filled contour plots visualization to map and display the values with a colormap.
Kindly refer to the given steps to achieve the same:
- Create the mesh grid and load your data from the “.txt” file:
[X, Y] = meshgrid(x, y);
data = load('file.txt');
- You can visualize the data as a 2D heatmap using a colormap, where each matrix value is automatically mapped to its corresponding (x, y) coordinate:
imagesc(X,Y, data);
axis xy;
colormap jet;
colorbar;
- You can also visualize the data as a 3D surface plot, which helps illustrate value variations across three dimensions with smooth color interpolation:
surf(X, Y, data)
shading interp
colormap jet
colorbar
xlabel('X'); ylabel('Y'); zlabel('Value')
The above code generates the following output:


Please refer to the following documentations to get more information on the related functions:
- surf: https://www.mathworks.com/help/matlab/ref/surf.html
- imagesc: https://www.mathworks.com/help/matlab/ref/imagesc.html
- colormap: https://www.mathworks.com/help/matlab/ref/colormap.html
- colorbar: https://www.mathworks.com/help/matlab/ref/colorbar.html
I hope this helps!
类别
在 帮助中心 和 File Exchange 中查找有关 Color and Styling 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!