hTeeML
hTeeML

Reputation: 61

How to record data automatically on excel that is generated on Matlab

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?

Upvotes: 0

Views: 81

Answers (1)

Daniel
Daniel

Reputation: 36710

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).

Upvotes: 2

Related Questions