Semicolon not suppressing MatLab output

In summary, the speaker is working in MATLAB and has created a function to calculate the intensity of an image. The function takes in an image file, processes it, and returns the intensity value. However, when calling the function, the entire matrix is being displayed in the command window instead of just the image and the time it takes to evaluate the function. The speaker is looking for assistance on how to suppress the matrix from being displayed.
  • #1
Agent M27
171
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
  • #2
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.
 

Related to Semicolon not suppressing MatLab output

What is a semicolon in MatLab and why does it suppress output?

A semicolon in MatLab is a statement terminator. When used at the end of a line of code, it tells MatLab to not display any output for that line of code. This is useful when you want to write multiple lines of code without the output cluttering the workspace.

Why does adding a semicolon sometimes not suppress output in MatLab?

Adding a semicolon at the end of a line of code does not suppress output if there is an error in that line of code. In this case, MatLab will display an error message, even with the semicolon. Additionally, some functions or operations in MatLab are designed to always display output, regardless of whether a semicolon is used or not.

Can I turn off the semicolon's output suppression in MatLab?

Yes, you can turn off the semicolon's output suppression by using the "diary" function in MatLab. This function redirects all the output to a file, instead of the workspace. You can also use the "fprintf" function to display output to the workspace without using a semicolon.

Is there an alternative to using semicolons for suppressing output in MatLab?

Yes, you can use the "disp" function in MatLab to display specific outputs to the workspace. This is useful when you want to display specific values or messages, instead of suppressing all output with a semicolon.

Can I suppress output for multiple lines of code in MatLab?

Yes, you can use a semicolon at the end of each line of code to suppress output for multiple lines. You can also use the "diary" function to redirect all output to a file, which will suppress all output in the workspace. Alternatively, you can use the "fprintf" function to display specific outputs without using a semicolon.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
481
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
10K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
Back
Top