필터 지우기
필터 지우기

Create surface plot from txt file with x y z coordinates.

조회 수: 34 (최근 30일)
Surfer
Surfer 2022년 6월 14일
답변: Sayan 2023년 8월 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)
Error using dlmread
The file 'mode shape 1.txt' could not be opened because: No such file or directory
  댓글 수: 1
Torsten
Torsten 2022년 6월 14일
편집: Torsten 2022년 6월 14일
Z must be a matrix, not a vector since Z(i,j) = Z(x(i),y(j))
plot3 plots a curve, not a surface. If x,y and z are vectors, then you cannot create a surface out of them.

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

답변 (1개)

Sayan
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:
Hope this helps in resolving the issue.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by