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

조회 수: 4 (최근 30일)
jop schilder
jop schilder 2019년 10월 17일
답변: Soumya 2025년 8월 4일
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
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: 
I hope this helps!

카테고리

Help CenterFile Exchange에서 Color and Styling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by