필터 지우기
필터 지우기

Plot data from a txt in a meshgrid

조회 수: 15 (최근 30일)
marco97f
marco97f 2022년 12월 5일
답변: Gokul Nath S J 2022년 12월 9일
Hi,
I have a .txt file with a single column of 10000 values, and I'd like to display these values as z-values in a x-y mesh grid made by 100x100 nodes. How can I arrange the values in a sort of 100x100 matrix and plot the surface made by z-values.
Thanks a lot!
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2022년 12월 5일
hello
use readmatrix to load the data from the txt file
then use reshape to convert your vector of 10,000 values to an 2D array of size 100 x 100 (pay attention how you want the data be reorganized in row or column directions)
then you can plot using one the many available functions of 3D plotting (surf, imagesc, plot3,...)

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

답변 (1개)

Gokul Nath S J
Gokul Nath S J 2022년 12월 9일
Hi Marco,
Please find an example code using the surf command.
data = readmatrix(file.txt);
data2d = reshape(data, 100, 100);
[X,Y] = meshgrid(1:100,1:100);
surf(X,Y,data2d);
You can replace file.txt with your text file.
Refer the following article for more information.

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by