How to I convert this to a 2d array?
Show older comments
I have a space delimited text file in the form of x y z and I want to create a 2d array so that I can plot the contour (using contourf) - what's the best way I can do that?
This is what the data looks like: (x y z)
23.48497963 13.19587040 60.91899872
24.03828049 13.26920033 61.01649857
24.63999939 13.42000008 60.59999847
24.76104927 13.37959957 61.06637955
18.97845078 12.31340027 61.88624954
19.23686028 12.50454998 62.81980896
19.55764008 12.43560028 61.80752945
And for the contourf function, it says that I need to format that into a 2d array (and I need to have the x and y be the indices.
I tried this:
f=fopen('68 data set.txt');
c=textscan(f,'%f %f %f','CollectOutput',true);
fclose(f);
out=accumarray(c{1}+1,c{2});
(from this: http://www.mathworks.com/matlabcentral/answers/116044-how-to-read-data-from-txt-file-and-to-create-a-2d-matrix )
And it gave an error: "Index exceeds matrix dimensions"
Also, is it true that I would have to sort the indices for the contourf function?
Your help is greatly appreciated.
Accepted Answer
More Answers (3)
Muhammad Usman Saleem
on 2 Apr 2016
0 votes
Solution is here
Please check it and accept my answer if this fulling your requirements
1 Comment
Kuifeng
on 2 Apr 2016
0 votes
Maybe can try the function plot3 instead of contourf.
f=importdata('68 data set.txt'); x = f(:,1); y = f(:,2); z = f(:,3); plot3(x,y,z);
Ewen Chan
on 2 Apr 2016
0 votes
Categories
Find more on Animation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

