How to Suppress Output in MATLAB Using eval()?

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

The discussion focuses on suppressing output in MATLAB when using the eval() function. By adding a semicolon at the end of the eval command, users can prevent the display of results in the command window. The example provided demonstrates creating 12 magic squares without displaying them, effectively allowing variable assignments without output clutter. This method is essential for maintaining a clean workspace in MATLAB.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of the eval() function in MATLAB
  • Knowledge of variable assignment in MATLAB
  • Basic concepts of magic squares in mathematics
NEXT STEPS
  • Explore MATLAB's documentation on the eval() function
  • Learn about variable management and workspace organization in MATLAB
  • Investigate alternative methods for creating magic squares without eval()
  • Research best practices for suppressing output in MATLAB scripts
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly programmers and data analysts looking to optimize their code by managing output effectively.

matematikawan
Messages
336
Reaction score
0
I get this example from >>help eval
and add a semicolon.for n = 1:12
eval(['M' num2str(n) ' = magic(n)']);
end

The above commands display all 12 magic square. How do I suppress the output? I only want MATLAB to assign the variables not display them.
 
Last edited:
Physics news on Phys.org

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K