1

I'm doing with MATLAB.

I have a file named 'cobat'. Cobat is a *txt file, tab delimited, consisted of 3 coloumns, so it's a table. I load it manually into this script:

I want users browse their own file. How can I do it? Is this code correct:

[filename pathname] = uigetfile(('.txt'), 'Browse Your File')

Here are my problems:

  1. I think it is only for text file, not tab delimited (table). I think I have to use uitable, but I don't understand how to implement it, because the file (cobat) should be loaded.

  2. And, if it has been implemented, I can't write 'cobat' in my script, like this:

[g c] = kmeans(cobat,k,'dist','SqEuclidean'); y = [cobat g]

Then I have to change 'cobat' to what name?

Thank you.

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
Alvi Syahrin
  • 373
  • 3
  • 7
  • 16

1 Answers1

1

You are on the right track. After locating the file you need to load it:

load([pathname filesep filename])

If file name is cobat (or cobat.txt), it will create a matrix called cobat in the workspace with the content of the file.

Simon
  • 31,675
  • 9
  • 80
  • 92
  • Thank you. But what about this line? `[g c] = kmeans(cobat,k,'dist','SqEuclidean'); y = [cobat g]` There is 'cobat', I have to change it to what? – Alvi Syahrin May 11 '13 at 05:30
  • You don't need to change it, it should work now that the variable `cobat` exists. – Simon May 11 '13 at 05:33
  • Thank you, Simon. But how if I load another file with another name? Is it okay to write 'cobat'? – Alvi Syahrin May 11 '13 at 05:46
  • You should read the manual page that I linked. You can use `load` to load the content of a file into a variable. For instance, `x = load('foo.txt');` loads the content of `foo.txt` into the variable `x`. – Simon May 11 '13 at 14:45