how do i plot a coordinate field with values for each specified coordinate?

4 views (last 30 days)
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!

Answers (1)

Soumya
Soumya on 4 Aug 2025
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: 
I hope this helps!

Categories

Find more on Color and Styling in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!