Semicolon not suppressing MatLab output

  • Context: MATLAB 
  • Thread starter Thread starter Agent M27
  • Start date Start date
  • Tags Tags
    Matlab Output
Click For Summary
SUMMARY

The forum discussion addresses the issue of MATLAB not suppressing output when a function is called, specifically when using semicolons. The user, Joe, is working with a function named intensity that processes an image and measures execution time. Despite using semicolons in the function, the output of the variable y is still displayed in the command window. The solution involves ensuring that a semicolon is also used when calling the function in the command window, as MATLAB defaults to displaying return values unless explicitly suppressed.

PREREQUISITES
  • Familiarity with MATLAB programming and syntax
  • Understanding of function creation and usage in MATLAB
  • Knowledge of image processing functions such as imread and imshow
  • Basic understanding of performance measurement using tic and toc
NEXT STEPS
  • Research MATLAB function output suppression techniques
  • Learn about MATLAB's default output behavior and how to control it
  • Explore advanced image processing techniques in MATLAB
  • Investigate performance optimization in MATLAB using tic and toc
USEFUL FOR

This discussion is beneficial for MATLAB programmers, image processing specialists, and anyone looking to optimize their MATLAB functions to control output visibility effectively.

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.
 

Similar threads

Replies
1
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K