Suppressing result using 'varname_' in Matlab

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

The discussion centers on the use of the 'varname_' function in MATLAB for dynamically storing variables within a loop. The user, Heidi, encountered an issue where results were printed to the command window despite using a semicolon to suppress output. The solution provided involves ensuring that the semicolon is correctly placed within the eval function to prevent output. Specifically, the correct command is 'eval(['F_' num2str((run-237)*10) '=F;']);' which effectively suppresses the output as intended.

PREREQUISITES
  • Familiarity with MATLAB programming and syntax
  • Understanding of dynamic variable naming in MATLAB
  • Knowledge of matrix data structures in MATLAB
  • Basic understanding of the eval function in MATLAB
NEXT STEPS
  • Explore MATLAB's eval function and its best practices
  • Learn about MATLAB's data import functions, specifically Dataimport
  • Investigate MATLAB's command window output suppression techniques
  • Study efficient memory management in MATLAB when handling large matrices
USEFUL FOR

MATLAB programmers, data analysts, and anyone working with large datasets in MATLAB who seeks to optimize their scripts and manage command window outputs effectively.

Heidis
Messages
2
Reaction score
0
Hey everybody
I have very recently learned the function 'varname_' for storing data with different names in a loop. My problem is that the result is written in the command window even though I have written ;.

My command looks like this

for run=237:273
[F,dt] = Dataimport(n,run);
eval(['F_' num2str((run-237)*10) '=F']);
clc
end

Since every F coming out of the function Dataimport is a 10x33,877 matrix I would very much like to stop Matlab from writing it 37 times (length of loop).

I have tried putting two ;; but that gave an error. Right now I'm just deleting the result for each loop but it still takes a lot of unnecessary power.

Can anyone help me and correct my mistake?

Regards Heidi
 
Physics news on Phys.org
How should I interpret the lak of response? Is it because you don't know how to solve the problem, maybe because this is just how Matlab has decided to do it, or because you cannot see why I'm even having this proplem?
Please let me know this as my script is increasing with more of these huge loops with new variables.
Regards Heidi
 
Instead of:

eval(['F_' num2str((run-237)*10) '=F']);

Try:

eval(['F_' num2str((run-237)*10) '=F;']);

Note the ; after F.
 

Similar threads

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