0

I am using MATLAB R2010b. I am doing clustering with k-means algorithm. And everytime it is executed, it always shows different result. And I want it to be saved, always, in Excel.

Here is the snippet of my code:

y = [data x];
xlswrite('clustering.xls', y, 'KMEANS', 'A1');

As I said before; everytime it is executed, it shows different result, so the clustering.xls is always updated, updated, and updated--without saving the old file. I want to save all the history. The only thing I think that can be solved this problem, is users rename their own file--but it is not efficient. So, I think I need a messagebox to let user enter the name of their xls file.

How to make it possible? Any idea?

I appreciate all the answers.

Thank you.

am304
  • 13,758
  • 2
  • 22
  • 40
Alvi Syahrin
  • 373
  • 3
  • 7
  • 16

3 Answers3

4

It would seems like you might find uiputfile useful for your task.
see doc: http://www.mathworks.com/help/matlab/ref/uiputfile.html

Shai
  • 111,146
  • 38
  • 238
  • 371
  • Thank you, Shai, for the answer, but uigetfile is simply not what I am looking for. It is used to import file. In this case, I want to **export** the file into excel. I have did it clearly (look at the snippet code), but I want to ask users to input the name of their own excel before it is exported. – Alvi Syahrin May 30 '13 at 11:24
  • @AlviSyahrin have you considered `uiputfile` that I mensioned? – Shai May 30 '13 at 11:38
2

Use the input function:

y = [data x];
xlsFileName = input('Enter the name for the xls file: ', 's');
xlswrite(xlsFileName, y, 'KMEANS', 'A1');
m_power
  • 3,156
  • 5
  • 33
  • 54
2

I would suggest a slightly different alternative, i.e. to write each set of results to a separate sheet in excel by changing the 3rd input.

The following loop demonstrates a basic example:

for ii = 1:10
    xlswrite('test.xlsx',rand(10),ii)
end

You will find out that he sheets are named sheet1, sheet2,...

You can also suppress the warning about the creation of new sheets with:

warning('off','MATLAB:xlswrite:AddSheet')
Oleg
  • 10,406
  • 3
  • 29
  • 57