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

4 visualizaciones (últimos 30 días)
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!

Respuestas (1)

Soumya
Soumya el 4 de Ag. de 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!

Categorías

Más información sobre Color and Styling en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by