Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine disk space in MATLAB

Tags:

matlab

Is there any function in MATLAB that determine free disk space? I have made a temporal function that uses MS-DOS dir command and parses the last line of its output. I think it's working as expected but I guess (1) it won't work in other systems (OS X, Linux, Unix, etx.) and (2) can also fail in different Windows versions. Perhaps someone could improve it to make it more generic? Thanks

The code:

function out = freediskspace
    [~,d] = dos('dir');
    C = textscan(d,'%s','Delimiter','\n'); C = C{1}{end};
    C = strrep(C,',','');
    r = regexp(C,'\d+','match');
    out = str2double(r{2});
end
like image 668
Celdor Avatar asked May 05 '16 07:05

Celdor


People also ask

How much disk space does MATLAB take?

Accepted Answer disk: 2 GB for MATLAB only, 4–6 GB for a typical installation. memory: 2 GB, or 4 GB if you use Simulink.

How do I find the directory of a file in MATLAB?

You can use genpath to make a list of all folders, then use dir() to see if the file you want is in that folder.

Why is MATLAB so large?

MATLAB is a paid software and it get regular updates, On the other hand Octave is an open source programming language. Therefore it doesn't get the regular updates and has limited features as compared with MATLAB. That's why MATLAB is 10 GB is size and Octave is only 300 MB.


1 Answers

You can use a Java call (this works on both Linux and Windows - I have not checked OSX but it should be fine).

function free = getFreeSpace(path)

    if nargin < 1 || isempty(path)
        path= '.';
    end

    free = java.io.File(path).getFreeSpace();

end

For example,

>> f = getFreeSpace('C:\')
f =
    3.9338e+11
like image 187
Chris Taylor Avatar answered Oct 05 '22 16:10

Chris Taylor