Can an mfile(s) written in Matlab on Windows be run on matlab for a Mac without compatibility issues?

23 views (last 30 days)
I am running matlab R2012a on my windows x64 system. Can I send someone an mfile who is running matlab on their mac and they won't have an issue running it?
Thanks

Answers (6)

Jan
Jan on 19 Sep 2012
Edited: Jan on 20 Sep 2012
Usually this works seamlessly. Most of the toolbox functions are provided as M-files and they run on all supported systems.
Some small details can differ, but there are built-in methods to handle them:
  • Use filesep and fullfile instead hard-coded file separators.
  • Do not rely on a certain location of the TEMP folder, but use the tempdir function.
  • The display of complex GUIs can differ in some details, e.g. the background color of buttons.
  • load failes for files in ASCII format, when the MacOS-9 line breaks CHAR(13) are used. It is easy to convert the files on demand. (Nevertheless, it is an ugly bug. I blame the DOS/MacOS/Linux designers, because they have not been able to define a common ASCII standard.)
  • set(0, 'PointerLocation', [x,y]) does not work under MacOS. Linux?

Thomas
Thomas on 19 Sep 2012
mfiles are script/function files which are dependent on MATLAB and not the underlying OS, unless you are making system call in your mfiles. So you shoudl be able to use an mfile created in windows on OSX as long all you have all the toolboxes you require on the MAC that you had on the windows machine that are called from the script..

Walter Roberson
Walter Roberson on 19 Sep 2012
Formatting of floating point numbers differs between OS-X and MS Windows.
Calculations may have different results on the two systems, due to differences in round-off and differences in compiler-level optimization. In some cases the differences can be substantial (in cases where very precise cancellation is important, or cases where the calculation is unstable.)
ActiveX can only be used in MS Windows. This includes the more advanced uses of Excel.
The graphics subsystems are different between the two. This can lead to subtle differences in plotting. It can also lead to major differences in fonts and appearance of lettering.
There are differences in media support.
  2 Comments
Walter Roberson
Walter Roberson on 19 Sep 2012
Also, MS Windows does not display numbers in full precision in some cases, which can lead to differences in files saved as text. The difference in the number of decimal places can be a fair bit.

Sign in to comment.


Dan Weaver
Dan Weaver on 15 Jul 2015
Two minor differences I've encountered:
Using "ls" won't necessarily work as expected on a Linux system if you're used to Windows. You might instead need to use "dir" or adapt your use of the ls output.
Using "\" to describe the path location won't work on Linux. Use "/" only.

Wayne King
Wayne King on 19 Sep 2012
Yes, unless that M file is using some specific Windows system commands, or is really a mex file compiled for Windows

Ken Atwell
Ken Atwell on 19 Sep 2012
As others have pointed out, differences are contained. I switch between Windows and Mac routinely, and my applications largely "just work". For me, assumptions about path separators (use filesep as Jan suggests), and keeping MEX-Files on both platforms in synch are the most common gotchas. Most toolboxes are available on both platforms, which some exceptions, mostly involving 3rd party interfaces for products not available for Macs anyhow.
I don't write a lot of GUI code, but I do know that DPI on Windows and OS X are different (one is 96 DPI, the other 72 DPI, but I forget which is which), so you may need to experiment to get a GUI that looks great on both platforms. For example, I wrote this experiment some time ago:
f=figure;
pos=get(f, 'Position');
str = '0123456789ABCDEF';
sz = 36;
if ismac sz = sz*(96/72); end
uicontrol('Style','text','Units', 'pixels', ...
'String',str, 'FontSize', sz, 'FontName', 'Courier',...
'Position', [0 0 pos(3) pos(4)]);
Experiment by comment out the "|if ismac|" statement -- note that MATLAB provides the functions ispc and ismac for convenience should you need to include platform-specific behavior.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!