フィルターのクリア

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 Center および File ExchangeSurface 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