I want a simple program that reads in sensor and based on the sensor data triggers a matlab function saved as .m file. How do I do this? Do I have to convert the file first?
That's a real-time application. Reading the sensor and triggering a signal or serial output based on the real-time reading is not a problem. As far as converting it to a .m file or sending it to matlab , someone else will have to address that.
Matlab running on the host computer can certainly monitor the serial port and take appropriate action, if the Arduino reports something on that port.