Datalogging Matlab on PC/Mac (Options: S function, Processing, ...)

Hi,
I am using Matlab Simulink to control my Arduino board and would like to log some data generated by the arduino. I have used this custom function which can log the data on a SD card (Data Logger on Arduino UNO - File Exchange - MATLAB Central). However, I want to have the ability to write the data on a file on my local computer as well. I have written my data on the Serial port using the Serial library. I can save data on the Serial port using a Serial monitor, but how can I do that from within Matlab or the above code?

One option is to use C commands to write the data. But I don't know why standard C functions like fstream or stdio (fopen, fclose) do not work here when called from matlab?

The other option is to use Processing language which can record from the serial port, but is there a way to call Processing from Matlab?

How is it possible that there is a library to write file on SD card but not on the computer?

Will be thankful if you could help me please. This has kept me busy over the last 2 weeks and I am really out of ideas.

I am using Matlab Simulink to control my Arduino board

How do you think that Matlab and the Arduino are exchanging information?

If you said "via the serial port", you are correct. It would then be up to Matlab to actually store the data that the Arduino sent.

Hmmm. You are right! All this time I was looking at the problem upside down. I guess I got too focused on the arduino side. Thanks again.

Ok, I take it back. When you load the model from Simulink on the arduino, there is no more communication between Matlab and Arduino. So you could run a separate code to write the information coming back from the Serial port but it wouldn't be automatically initiated by the Arduino the way it is with the SD card. Right?

When you load the model from Simulink on the arduino, there is no more communication between Matlab and Arduino.

Bullshit.

Thanks for the elaborate response. I thought we are here to help eachother not to bully eachother. If there is something I am missing I will appreciate it if you could let me know.

Thanks

If you have Matlab running, communicating with the Arduino, it IS using the serial port. NO other application can also use the serial port that the Arduino is on. Therefore, if you are going to get data from the Arduino to the PC, somehow, someway, Matlab MUST be the application that reads the data and writes it to the file.

Maybe I did not explain my problem correctly.
So my question is, if I upload my simulink model on to the board, now the board can run the task independently from Matlab. I can include a datalogging module in my Simulink model which makes the Arduino board able to log data on the SD card. Now what should I do if I want the board to do exactly that on the computer (on some specific folder) when connected using the serial port but in the absence of Matlab? Or for that matter, in the absence of any other softwares like Processing or a serial monitor?

Thanks

Now what should I do if I want the board to do exactly that on the computer (on some specific folder) when connected using the serial port but in the absence of Matlab?

Do you understand what the Arduino is capable of? It can write to the serial port. It can write any data you want to write to the serial port. That could include the data that is currently being written to the SD card.

But, to what end? There MUST be some application on the other end of the serial port that cares about the data. You need to write an application that listens to the serial port and magically makes the serial data appear in a file in some specific folder on the PC.

The Arduino can NOT do it by itself.

Ok, I see what you mean. I was hoping I could run a C command line on Arduino which would make it possible for the Arduino to write a file on the PC as well (essentially write what is on the serial port to the computer). Thanks again for your help.

Cheers,
Mohsen

I know of one matlab function for streaming data from a serial port, maybe it works well for what you are trying to acheive? Haven't tried it but you could give it a shot: serialDataStream - File Exchange - MATLAB Central
You could modify the function to continously output your data as ascii files.

Also a more recent function for plotting arduino data in matlab: http://www.mathworks.com/matlabcentral/fileexchange/50589-plot-arduino-data-on-matlab