1

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.

2 Answers 2

3

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,:));
Sign up to request clarification or add additional context in comments.

6 Comments

Error using ==> fscanf Invalid file identifier. Use fopen to generate a valid file identifier. it is showing this error.
the error says it all by itself: have you opened your file first using fid=fopen('name_of_your_file') ?
it's a .dat file so do i need to write something else?
you said you had your data in three columns as showed in your question^^ so that looks like plain text to me. If that's the case, just put the name of your file there: fid=fopen('name_of_your_file.dat_or_whatever') And btw: it doesn't hurt to try things out yourself...
thanks !!! can u please tell me how can i add extra features to my plot{ex. color,surface} ?
|
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.