Echo off or semicolon in GUI

This might be very basic (stupid) question but I will ask anyway. Does eat make sense to use echo off in a matlab GUI, and does it make the program run faster? Which is the preferred, echo off or semicolon after each function. And finally, how do I place/use the echo off in a GUI code. Thanks from a novice.

 Accepted Answer

OCDER
OCDER on 29 Sep 2017
  • It makes sense to use echo off pretty much every time. Although echo on is used for debugging purposes, there are better way to debug code via error messages and the debugger.
  • echo off is faster, no time spent printing message.
  • always use semicolon to suppress function outputs. It should be a habit to use ";" as many programming languages uses the semicolon to end a statement.
  • if you use semicolon, you don't have to place echo off in your GUI, unless you want it to turn echo on / off as part of a debugger option for your GUI.

5 Comments

Thanks for a great answer Donald. One final one: do you use semicolon after each line or only after the “function” line?
I routinely use semi-colon after every statement, except for the control statements and parts of control statements. For example,
if this > that
do_something;
end
where some people might go as far as
if this > that;
do_something;
end;
The editor will warn that some of those semi-colons are not needed.
There are some statements that cannot generate output, but I tend to put semi-colons after them anyhow:
hold on;
set(gca, 'XTick', 1:20);
I am inconsistent as to whether I put a semi-colon after a set() call. "set" can produce output in some uses.
Here's an example of how I write code, based on another question I just answered. As you can see, no semicolon after the function line. Semicolon everywhere else, EXCEPT for, end, if, switch, case. When in doubt, use semicolon as it doesn't hurt.
function wordcount = getWords
str = 'jeff john 2lion lion2 this2that dog.';
strcell = regexpi(str, '\w*', 'match');
%Defining word as one that starts with a letter (this2that would still be a word)
wordloc = cellfun(@(x) ~isempty(regexpi(x(1), '[a-z]')), strcell);
wordcount = sum(wordloc); %number of words
nonwordcount = sum(~wordloc); %number of non-words
%Displaying words
for j = 1:length(wordloc)
if wordloc(j)
fprintf('Is a word: %s\n', strcell{j});
end
end
The Editor in Matlab should kind of give you warnings and suggestion for formatting code. Also try opening up some matlab built-in function to see how the pros do it, like :
open csvread
Hi Robert and Donald. Thanks a lot for the answers and examples. Great help.
You're Welcome!

Sign in to comment.

More Answers (0)

Categories

Find more on Software Development Tools in Help Center and File Exchange

Products

Tags

Asked:

on 29 Sep 2017

Commented:

on 29 Sep 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!