3
fid =fopen(datafile.txt','r');  
data = textscan(fid, '%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f');  
plot3(data(:,5),data(:,6),data(:,7))  
fclose(fid);

I am getting the error:

Error using plot3
Not enough input arguments.

Where am I going wrong here? my data file is just columns of doubles (hence %f)

1
  • Did you check if data is actually fetching the correct information from the text file? Commented Jun 20, 2017 at 17:06

1 Answer 1

2

This is one of those cases where the error isn't very informative. The problem here isn't that there aren't enough input arguments, it's that they are of the wrong type...

Your problem is that textscan actually returns the loaded data in a 1-by-N cell array, where N is the number of columns (i.e. format specifiers, like %f) in your file. Each cell holds one column of data. You need to extract the contents of the cells using curly braces in order to pass it to plot3, like so:

plot3(data{5}, data{6}, data{7});
Sign up to request clarification or add additional context in comments.

2 Comments

Shouldn't it be data{5}, data{6} and data{7}? I believe the nested cell array contains individual cells where each cell represents a column of what you're looking for. Also data{:, 5} would produce a comma-separated list so I'm not sure what it would produce when being called with plot3.
@rayryeng: Yes, it's clearer to write it as data{5}, but it should still work even as data{:, 5}, since the first dimension should be of size 1 (the default output from textscan is always 1-by-N, I believe).

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.