0

There was a similar topic How to export Simulink data to the MATLAB Workspace during simulation?. pm82 answered that this is possible using set and get commands. But I didn't understand how to use timer callbacks to read the data! Can anyone pls explain it to me?

However, in the above question they discussed how to write Simulink data into the MATLAB Workspace. I want Simulink to write data into Excel during the simulation so that that data can be read by another application in real-time. Is there any way to do that?

I really appreciate any help.

Phil Goddard
  • 10,571
  • 1
  • 16
  • 28
  • I think I was not clear. I meant I need simulink writes its data corresponding to each step in an excel file such that it is possible to read this data real-time from excel. Is this possible? – user1907354 Oct 21 '18 at 07:09
  • What (sample rate) do you consider to be 'real-time'? You are running two non-real time applications (MATLAB and Excel) on a non-real time OS (Windows). Unless you are talking about sample rates measured in seconds (or longer) then you've got almost no hope of running 'real-time'. – Phil Goddard Oct 21 '18 at 15:33
  • The sample rate of my simulink model is 0.001sec however I want to read data from simulink and write in excel with a sample rate of 5 minute. I know that the clock of simulink is not synchronized with a real clock but first I want to find a way to write simulink output in excel according to simulink clock every 5 min. IS this possible? – user1907354 Oct 21 '18 at 18:23
  • Yes. Do you want all data (that would nominally be written to the MATLAB Workspace) or just one or two signals? – Phil Goddard Oct 21 '18 at 23:53
  • The whole simulation time is 24 hour I want the data of four signals every 5 min. – user1907354 Oct 22 '18 at 03:03
  • @Phil Goddard Could you pls tell me the solution? – user1907354 Oct 23 '18 at 03:22
  • 1
    You should write an S-Function. It's input would be the signals that you want to write to file. Within the S-function you could just use `xlswrite` to write the data (probably keeping track of the cells that should be written to next). Since `xlswrite` is relatively slow this isn't particularly efficient, but if you only need to do it every 5 minutes in a simulation with a step size of 0.001 then you will probably get away with it. Note that if you have another application also accessing the generated Excel file then you'll need to worry about who has control of the file at any given time. – Phil Goddard Oct 24 '18 at 16:15

0 Answers0