Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Semicolon not suppressing MatLab output

  1. Jun 15, 2011 #1
    I am working in matlab and have created a function, which I will call in the command window. Here is the code:

    Code (Text):

    function y=intensity(img)
    im = imread(img);
    R = im(:,:,1);
    G = im(:,:,2);
    B = im(:,:,3);
    r = im2double(R);
    g = im2double(G);
    b = im2double(B);
    rgbsum = r + g + b;
    intensity = rgbsum/3;
    y = intensity;
    All I want is to see the image produced and the time it takes for the function to evaluate, however it is printing the entire matrix, it is not printing the time it takes, and it does show the image so no problem there. The problem is that the images are very large, roughly 1000 x 1000 matrices, so I don't want all of that in the command window. I have used semicolons everywhere but still cannot figure out how to suppress 'y'. Any assistance is much appreciated.

  2. jcsd
  3. Jun 15, 2011 #2


    User Avatar
    Science Advisor

    If this is a proper function (and saved in a .m file with the function name), you'll still need to put in a semicolon when calling the function. MATLAB's default behaviour is to show all your return arguments, unless they're suppressed. For instance,

    >> intenseMatrix=intensity('MatlabLogo.png');

    For what it's worth, your code works when I try it on a sample file (along with two toc outputs). You may want to run the procedure a few times if things are happening too fast (0.00... seconds), or if you have discrepancies between the time you call the first toc and the time the disp(toc) runs.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook