0

I am new to MATLAB and I currently have a script that generates different values for a variable n every seconds. So I end up with 100s of data that needs to be transferred to excel. Currently, I do this manually by copying pasting each but it does take really long.

I thought about using xlswrite command but that just writes data on the first column and keeps overwriting that column as new data is generated.

Would you be able to help me or lead me to easier way with this?

hTeeML
  • 61
  • 8
  • 1
    It's easy to write to a csv file in MATLAB and keep appending to the end of the file (instead of overwriting). Is that a sufficient solution? You could also keep track of all the data in MATLAB, and then write a full xls file every time. – Matthew Gunn Mar 01 '16 at 23:03
  • 1
    Thank you, I found out about dmlwrite append command, I will be using that. – hTeeML Mar 02 '16 at 00:03

1 Answers1

2

If you really want to write directly to excel while your code runs, you can use activex. Some well documented example code can be found in this answer. Somewhere in the middle you find this code:

% select a 5x5 range, and fill it with some numeric values
sheet.Range('A1:E5').Value = num2cell(magic(5));

Here you have replace it with a loop which continuously writes the data.

Be careful when using this solution.

  • Problems with Excel can stop your MATLAB process
  • Especially with large data it will be much slower than post-processing
  • You are forced to have Excel and MATLAB on the same PC installed

Using a simple text file which is continuously written might be the better choice, either fprintf(use the same file handle and it will append) or dlmwrite(use append option).

Community
  • 1
  • 1
Daniel
  • 36,610
  • 3
  • 36
  • 69
  • 1
    Thank you for your reply I think for now I will be using dmlwrite which seems the easiest and working option. – hTeeML Mar 02 '16 at 00:15