3

How is it possible in MATLAB to determine if the OS is x64 or x86?

NOTE: I have found the computer function but it is mentioned that in case a x32 MATLAB is running on a x64 OS then it returns x32 (instead of x64) so this function will not do.

niels
  • 760
  • 8
  • 25
  • 1
    I was going to suggest `getenv('PROCESSOR_ARCHITECTURE')`, but that seems to return 'x86' in 32-bit MATLAB. – Nzbuu Sep 22 '11 at 19:21
  • 1
    Why do you need this? If you are using a matlab extension it would have to be compiled for the matlab version (x32 or x64) ... – Foo Bah Sep 22 '11 at 19:28
  • @FooBah: I need to know this explicitly so I can `dos(thecorrectfile.bat)` based on what OS (x32/x64) I am running on – niels Sep 22 '11 at 19:35

2 Answers2

3

From your comment, I assume you're running Windows.

Take a look at the environment variables PROCESSOR_ARCHITECTURE and PROCESSOR_ARCHITEW6432. The combination of their presence and values will tell you what you're running under.

x64 Matlab on x64 Windows:
PROCESSOR_ARCHITECTURE=AMD64

x86 Matlab on x86 Windows:
PROCESSOR_ARCHITECTURE=x86

x86 Matlab on x64 Windows:
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64

Then you can use the environment variables PROGRAMFILES, PROGRAMFILES(X86), and PROGRAMW6432 to find the right "Program Files" path to launch your external app from, if it's installed in the conventional location.

Google "WoW64" for more info on how the Windows x64 and x86 environments interact.

Andrew Janke
  • 23,508
  • 5
  • 56
  • 85
  • Thank you, the info you provided seems correct based on http://msdn.microsoft.com/en-us/library/aa384274%28v=vs.85%29.aspx. I've checked the first case (x64 matlab on x64 win) which applies to me. If anyone could also check the other two cases then the question is solved – niels Sep 22 '11 at 20:49
1

On Windows, you could try parsing the output of dos('systeminfo'), but it's not exactly fast. On Linux, you could try parsing the output of unix('uname -a').

Nzbuu
  • 5,241
  • 1
  • 29
  • 51
  • Thanks, that could be a solution. I'm running x64 Win 7 and it returns "x64 based PC" at "System type". Would this be "x32 based PC" if I were running x32 Win on x64 hardware? – niels Sep 22 '11 at 19:28
  • Try this in MATLAB `winqueryreg('HKEY_LOCAL_MACHINE', 'HARDWARE\DESCRIPTION\System\CentralProcessor\0', 'Identifier')`. I get "Intel64 Family 6 Model 23 Stepping 10" as a response from which it is obvious that I run a x64 OS. Those who can, please run the command and write the feedback (OS you are running and if your hardware supports the x64 architecture) – niels Sep 22 '11 at 20:09