how to plot 3D using a txt file

23 views (last 30 days)
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 Comments
Steve Eddins
Steve Eddins on 23 Sep 2020
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 on 23 Sep 2020
first column is theta
second one is phi
third is Ds
I wanted plot of theta vs phi vs Ds

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 23 Sep 2020
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);

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!