MATLAB Answers


Read out "Sudden Motion Sensor" in Macbook Pro

Asked by Hans
on 6 Jul 2013
Has anybody out there ever tried to access
the "Sudden Motion Sensor" present in any
Macbook via Matlab? I searched the whole
web but couldn't find an obvious solution.


Sign in to comment.

1 Answer

Answer by Ken Atwell
on 6 Jul 2013
 Accepted Answer

I'm not aware of anyone having done this. Apple apparently does not provide a Cocoa API to it, leaving you with informal, "tinkers" interfaces. A Stack Overflow article has some suggestions -- you would need either write some MEX glue code to interface Objective-C to MATLAB, or you may be able to use loadlibrary.
Another option would be to use this library, written Java. MATLAB has an interface to Java, so in theory this may be the easiest option.
In all cases, it looks like the options out there may not have been updated in the last handful of years, so they may or may not work with modern hardware (I'm guessing here). Also note that newish SSD drives do not have this hardware in question.


Thanks for the fast and informative answer! Great, thank you!
I already started to try to implement what you denoted as easiest option, namely using the java library from .
However, somehow it does not yet work, probably due to my inabilities... Despite of having used
javaaddpath .../sms/library/sms.jar
calling sms.Unimotion gives an error
>> sms.Unimotion.getSMSArray()
??? Undefined variable "sms" or class
Any Ideas?
This library was compiled in 2006, so my first guess is an 32/64 bit issue. Run this in the Terminal window:
cd path/to/file
file libUnimotionLib.jnilib
The file libUnimotionLib.jnilib was compiled for PowerPC and 32-bit Intel. All MATLAB releases on the Mac in recent years are 64-bit apps. This C library will need to be recompiled for 64-bit. Off the top of my head, I don't know how to compile native C code into a JNI library, sorry.

Sign in to comment.