How to I convert this to a 2d array?
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (3)
Muhammad Usman Saleem
le 2 Avr 2016
0 votes
Solution is here
Please check it and accept my answer if this fulling your requirements
1 commentaire
Ewen Chan
le 2 Avr 2016
0 votes
Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


