user1585645
user1585645

Reputation: 21

3d plot from xyz data in file

Can someone tell me how can I plot a 3d graph in matlab if I have the data in a single file in three column format like this:

48.000000     0.017723     0.400000
48.500000     0.017467     0.400000
49.000000     0.017209     0.400000
49.500000     0.016943     0.400000
50.000000     0.016664     0.400000
50.500000     0.016361     0.400000
51.000000     0.016022     0.400000
51.500000     0.015628     0.400000
52.000000     0.015151     0.400000
52.500000     0.014539     0.400000
53.000000     0.013709     0.400000

Each column represents a variable (3 axis) and all 3 vary.

Upvotes: 1

Views: 17498

Answers (2)

padmarao
padmarao

Reputation: 11

just try this code,

a=importdata('file.txt');%file_name.extension
plot3(a(:,1),a(:,2),a(:,3));

it's very easy and works fine too.

Upvotes: 1

Gunther Struyf
Gunther Struyf

Reputation: 11168

Use fscanf and plot3:

fid=fopen('data.txt');
XYZ=fscanf(fid,'%f %f %f',[3 Inf]);
fclose(fid);

plot3(XYZ(1,:), XYZ(2,:), XYZ(3,:));

Upvotes: 3

Related Questions