Code covered by the BSD License  

Highlights from
hostname.m

4.0

4.0 | 1 rating Rate this file 0 Downloads (last 30 days) File Size: 1.4 KB File ID: #24096

hostname.m

by Phillip M. Feldman

 

13 May 2009 (Updated 14 May 2009)

Report the name of computer on which Matlab is currently running.

| Watch this File

File Information
Description

This function reports the name of computer on which Matlab is currently running, and works under multiple operating systems.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
13 May 2009 John D'Errico

Despite the claim, this fails to run on all operating systems. Try it on a PPC Mac. No go.

unix('hostname') works fairly well if you are on a PPC mac. I've not verified it is correct for an intel mac.

14 May 2009 Thierry Dalon

(For windows only?)
Be aware: the call to unix('hostname') or system('hostname') gives you an empty sign a the end. You need to DEBLANK it!

See example:
[status,name]= unix('hostname')

status =

     0

name =

RBGD0SGC

>> length(name)

ans =

     9

That is to my opinion the only benefit for such an easy wrapper function else.

14 May 2009 John D'Errico

Macs will return either of MACI or MAC, depending upon whether the system is an older or new inter Mac system. The help for computer.m states this fact.

So hostname still fails to work on older MAC systems, although it will probably now run on intel based macs.

Also, this submission too has the flaw that it has a blank comment line BEFORE what serves as an H1 line. Since that disables lookfor, it is a flaw, and a silly one. I'm not at all sure why the author insists on doing this. It is unfriendly to disable a very useful feature of MATLAB for absolutely no good reason.

14 May 2009 us

use of java system calls is (likely) a more os independent way to retrieve such information, eg,

http://www.mathworks.com/matlabcentral/fileexchange/20321

us

Please login to add a comment or rating.
Updates
13 May 2009

minor modification to support Mac

14 May 2009

Added one line of code to strip any trailing blanks from the result.

14 May 2009

I updated this to support both the newer and older Mac environments.

Tag Activity for this File
Tag Applied By Date/Time
hostname Phillip M. Feldman 13 May 2009 09:23:12
host Phillip M. Feldman 13 May 2009 09:23:12
computer name Phillip M. Feldman 13 May 2009 09:23:12
windows Phillip M. Feldman 13 May 2009 09:23:12
linux Phillip M. Feldman 13 May 2009 09:23:12

Contact us at files@mathworks.com