how to plot 3D using a txt file

조회 수: 38 (최근 30일)
Nagendra Kamath
Nagendra Kamath 2020년 9월 23일
댓글: Ameer Hamza 2020년 9월 23일
I want the following graph
I tried using mesh and surf it is showing error that data should be matrix not scalar my txt file is attached below please help me solve this
  댓글 수: 2
Steve Eddins
Steve Eddins 2020년 9월 23일
I can't figure out how the numbers in chalitp.txt correspond to the graph you are trying to make. Can you clarify what the numbers in the file mean? Which numbers are supposed to the surface height?
>> load chalitp.txt
>> chalitp
chalitp =
45.0000 90.0000 106.7730 0.9351 0.8177
90.0000 90.0000 99.4950 0.8714 0.6616
54.7356 -45.0000 97.6599 0.8553 0.6257
90.0000 45.0000 97.3437 0.8525 0.6196
65.9052 63.4349 99.3358 0.8700 0.6584
25.2394 -45.0000 101.6240 0.8900 0.7050
25.2394 45.0000 102.7843 0.9002 0.7294
90.0000 45.0000 102.8373 0.9006 0.7306
65.9052 26.5651 111.1650 0.9736 0.9228
11.4218 -45.0000 114.1827 1.0000 1.0000
Nagendra Kamath
Nagendra Kamath 2020년 9월 23일
first column is theta
second one is phi
third is Ds
I wanted plot of theta vs phi vs Ds

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 9월 23일
I assume that first 3 columns are x, y, and z values. You need to use scatteredInterpolant
data = readmatrix('chalitp.txt');
x = data(:,1);
y = data(:,2);
z = data(:,3);
f = scatteredInterpolant(x, y, z);
xg = linspace(min(x), max(x), 20);
yg = linspace(min(y), max(y), 20);
[Xg, Yg] = meshgrid(xg, yg);
Zg = f(Xg, Yg);
surf(Xg, Yg, Zg);
  댓글 수: 2
Nagendra Kamath
Nagendra Kamath 2020년 9월 23일
Thank you it worked
Ameer Hamza
Ameer Hamza 2020년 9월 23일
I am glad to be of help!!!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by