views:

5879

answers:

3

How can I determine if I'm running on a 32bit or a 64bit version of matlab?

I have some pre-compiled mex-files which need different path's depending on 32/64bit matlab.

edit Found solution

The function computer returns the architecture I'm running on. so:

switch computer
    case 'GLNX86'
        display('32-bit stuff')
    case 'GLNXA64'
        display('64-bit stuff')
    otherwise
        display('Not supported')
end

works for me

+1  A: 

Does this really work? Which version of matlab are you using?

As far as I'm aware the 64 bit platforms end with "64" not 86. From the matlab site http://www.mathworks.com/access/helpdesk/help/techdoc/ref/computer.html I don't think that computer will ever return GLNXA86 but GLNXA64 instead.

So this question is specific to GNU Linux 32bit or 64bit version.

If you are testing for any 64bit platform then you probably need to test the last 2 characters to find "64" i.e. something like

if regexp(computer,'..$','match','64'),
   % setup 64bit options
else,
   % 32bit options
end

HTH

Adrian

Adrian
+3  A: 

The question of 32 vs. 64 bits is really a red herring. If I understand correctly, you want to determine which set of compiled MEX files are needed so you can set the path appropriately. For this, you can use the function mexext:

>> help mexext
 MEXEXT MEX filename extension for this platform, or all platforms. 
    EXT = MEXEXT returns the MEX-file name extension for the current
    platform. 

    ALLEXT = MEXEXT('all') returns a struct with fields 'arch' and 'ext' 
    describing MEX-file name extensions for all platforms.

    There is a script named mexext.bat on Windows and mexext.sh on UNIX
    that is intended to be used outside MATLAB in makefiles or scripts. Use
    that script instead of explicitly specifying the MEX-file extension in
    a makefile or script. The script is located in $MATLAB\bin.

    See also MEX, MEXDEBUG.
Vebjorn Ljosa
+4  A: 

Taking up on ScottieT812 and dwj suggestions, I post my own solution earn some points.

The function computer returns the architecture I'm running on. so:

switch computer
    case 'GLNX86'
        display('32-bit stuff')
    case 'GLNXA64'
        display('64-bit stuff')
    otherwise
        display('Not supported')
end

works for me

peje