I have three versions of your CLC that I have as shortcuts. They all came from here The biggest hammer is
This sometimes causes issues with the command window moving and files needing to be closed, but it really gets the job done. The second is a slightly smaller hammer that is based on the longer answer to the question. The third is the same as the second, except it doesn't screw with the path, current directory, or command window contents.
function MonitorPositions = getmonitorpositions()
error(nargchk(0, 0, nargin, 'struct'));
error(nargoutchk(0, 1, nargout, 'struct'));
Monitors = ...
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment.getScreenDevices;
MonitorPositions = zeros(length(Monitors), 4);
for iMonitors = 1:length(Monitors)
MonitorBounds = Monitors(iMonitors).getDefaultConfiguration.getBounds;
MonitorPositions(iMonitors, :) = ...
[MonitorBounds.getX, MonitorBounds.getY, ...
MonitorBounds.getWidth, MonitorBounds.getHeight];
end
end
I also like
function [UserNameString, HostNameString, IpAddressString, MacAddressString] = getcomputer()
error(nargchk(0, 0, nargin, 'struct'));
error(nargoutchk(0, 4, nargout, 'struct'));
UserNameString = char(java.lang.System.getProperty('user.name'));
HostNameString = char(java.net.InetAddress.getLocalHost.getHostName);
Eth0Obj = java.net.NetworkInterface.getByName('eth0');
MacAddressString = sprintf('%c%c-%c%c-%c%c-%c%c-%c%c-%c%c', dec2hex(mod(double(Eth0Obj.getHardwareAddress()), 256))');
Temp = Eth0Obj.getInterfaceAddresses.size-1;
IpAddressString = sprintf('%d.%d.%d.%d', mod(double(Eth0Obj.getInterfaceAddresses.get(Temp).getAddress.getAddress), 256));
end
8 Comments
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100417
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100417
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100419
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100419
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100428
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100428
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100430
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100430
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100437
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100437
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100577
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100577
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100603
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100603
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100615
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/48658-share-your-favorite-snippet-or-utility#comment_100615
Sign in to comment.