write a function to count the number of semicolons in a github repo given a url in matlab

To count the number of semicolons in a GitHub repo given a URL in MATLAB, we first need to obtain the contents of the repo. This can be done using the websave function in MATLAB. Once the contents are obtained, we can count the number of semicolons using regular expressions.

Here's a function that accomplishes this:

main.m
function num_semicolons = count_semicolons_in_repo(url)
    % Download contents of repo
    temp_zip = websave('temp.zip', url);
    unzip(temp_zip);
    
    % Count number of semicolons in each .m file
    num_semicolons = 0;
    mfiles = dir('**/*.m'); % Get all .m files in repo
    for i = 1:length(mfiles)
        contents = fileread(mfiles(i).name);
        num_semicolons = num_semicolons + length(regexp(contents, ';'));
    end
    
    % Clean up
    delete('temp.zip');
    delete('**/*.m'); % Delete all .m files in repo
end
538 chars
18 lines

This function takes a URL as input and returns the number of semicolons in all .m files in the corresponding GitHub repo. Note that this function downloads the entire repo, so it may not be suitable for large repos. Also, it deletes all .m files in the repo, so use with caution.

gistlibby LogSnag