The semicolon at the end of the sprintf statement doesn't stop the information displaying in the command window, what have I done wrong?
4 views (last 30 days)
Show older comments
The aim overall is to get a gas particle to move in a matrix, which I have mostly done. However, for it to run properly the values from the statement below cannot show in the command window.
b = sprintf('At the value x=%d, y=%d the value of a=%d',x ,y,a(x, y));
1 Comment
Stephen23
on 11 Dec 2017
Edited: Stephen23
on 11 Dec 2017
"The semicolon at the end of the sprintf statement doesn't stop the information displaying in the command window" Except that it does, so your bug must be in some other code and not the code that you have shown us.
Demonstrating that the semi-colon works is very simple:
>> x = 2;
>> y = 3;
>> a = rand(9,9);
>> b = sprintf('At the value x=%d, y=%d the value of a=%d',x ,y,a(x, y));
>>
Accepted Answer
Steven Lord
on 11 Dec 2017
If you have that sprintf statement inside a function, return the output of that sprintf call from the function, and call that function without a semicolon you will see the sprintf output. Put the following lines of code in example372339.m:
function example372339
outputOfSubfun = mysubfun()
function y = mysubfun
y = sprintf('Hello world!');
Now call this with:
example272339;
You should see the contents of the variable outputOfSubfun ('Hello world!') displayed even though the sprintf call ended with a semicolon.
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!