-4

I have a data file having 50 2-D data points written in Notepad. I want to use it in clustering algorithm to cluster these 50 points. How can I import this file? Is there any other way to use it in program?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
user1416605
  • 71
  • 1
  • 2
  • 7

3 Answers3

1

You can save the data as a .csv file or you can save it to an excel spreadsheet and use xlsread(). See here for more info: http://www.mathworks.com/help/techdoc/ref/xlsread.html

For the .csv case, this post should prove helpful: Fastest way to import CSV files in MATLAB

Community
  • 1
  • 1
Adam27X
  • 889
  • 1
  • 7
  • 16
1

Imagine you had the following data:

X = [randn(100,2)-1 ; randn(100,2)];
save data.mat X

Then its as simple as doing:

%# load data from MAT-file
load data.mat

%# cluster into K=2 clusters
C = kmeans(X,2);

%# show cluster assignment
gscatter(X(:,1), X(:,2), C)

screenshot

Amro
  • 123,847
  • 25
  • 243
  • 454
1

It depends how you have formatted the data file. You say it is saved on notepad but that is not too helpful. Depending on what you have used as the data delimiter you can import the datafile into an array using the dlmread function. For example if your file is called filename.dat and have used a ; character to separate each data item within this file you could read the data into a matrix A using

    A = dlmread("filename.dat",';');

I would suggest reading the help documentation on the dlmread function in matlab.

mathematician1975
  • 21,161
  • 6
  • 59
  • 101