Create surface plot from txt file with x y z coordinates.
조회 수: 23 (최근 30일)
이전 댓글 표시
I am trying to plot a 3D surface from the x y and z coordinates that I obtain in a txt file with three columns representing x, y and z values.
I can extract the x, y and z values and create 3 seperate column matrix and then I try to plot the x, y and z using the surf function but it returns an error stating - "Z must be a matrix, not a scalar or vector". However it plots correctly if I use the command plot3(x,y,z) but it does not creates a surface and also in plot3 z has no negative values.
I will insert the code here,
clear all;
close all;
clc
A=dlmread('mode shape 1.txt');
x=A(:,1);
y=A(:,2);
[X,Y]=meshgrid(x,y);
Z=A(:,3);
surf(X,Y,Z)
댓글 수: 1
답변 (1개)
Sayan
2023년 8월 30일
I understand that a 3D surface plot needs to be plotted from the x, y, and z coordinates extracted from the text file. However, here creating a "meshgrid" is not required. Only plotting the x, y, and z data with the "surf" function will work. "Z" is just a column vector whereas "X" and "Y" are matrices with size equal to the product between the "length(y)" and "length(x)". It can be plotted as shown below.
A=dlmread('mode shape 1.txt');
x=A(:,1);
y=A(:,2);
z=A(:,3);
surf(x,y,z)
For further assistance with the "surf" and "meshgrid" functions you can refer to the following MATLAB documentation:
- https://in.mathworks.com/help/releases/R2019b/matlab/ref/surf.html
- https://in.mathworks.com/help/releases/R2019b/matlab/ref/meshgrid.html
Hope this helps in resolving the issue.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!