Semicolon not suppressing MatLab output

  • Context: MATLAB 
  • Thread starter Thread starter Agent M27
  • Start date Start date
  • Tags Tags
    Matlab Output
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 11K views
Agent M27
Messages
169
Reaction score
0
I am working in MATLAB and have created a function, which I will call in the command window. Here is the code:

Code:
function y=intensity(img)
tic
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;
toc
disp(toc)
imshow(y)

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.

Joe
 
Physics news on Phys.org
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.