MATLAB Answers

0

surf plot from text file

Asked by son nguyen xuan on 21 Aug 2019
Latest activity Commented on by Akira Agata
on 21 Aug 2019
i have text with data an di dont know how to create a surface plot using surf function.
load('exportfilecst4.txt');
X = exportfilecst4(:,1);
Y = exportfilecst4(:,2);
z1 = exportfilecst4(:,4);
z2 = exportfilecst4(:,5);
z3 = exportfilecst4(:,6);
Z = z3;
plot3(X,Y,Z,'*','markerSize',3);
grid on
this is my code right now
i have attach the text file bellow
can anyone change it to surface plot

  0 Comments

Sign in to comment.

1 Answer

Akira Agata
Answer by Akira Agata
on 21 Aug 2019
 Accepted Answer

Like this?
data = dlmread('exportfilecst4.txt');
x = data(:,1);
y = data(:,2);
z = data(:,6);
figure
surf(reshape(x,31,[]),reshape(y,31,[]),reshape(z,31,[]))
surf.png

  3 Comments

son nguyen xuan's incorrectly accepted "Answer" moved here:
oh thank you so much
i'm sorry can you explain further how would you choose number 31? cause when i apply the code to another file, it can not produce a result
thank you
Akira Agata
on 21 Aug 2019
Hi son nguyen xuan-san,
This is because, looking at your data, x (=> 1st column) value repeats 31 times.

Sign in to comment.