Question on function variables i.e. ~
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Seetha Rama Raju Sanapala
el 17 de Dic. de 2015
Editada: Walter Roberson
el 17 de Dic. de 2015
[~,I] = max(abs(xc));
This is code taken from an example in MATLAB. I read somewhere that ~ can be used to indicate 'don't care' variables - variables that are not required in further program.
I could have used some variable name, say a, instead of ~, and ignore a. What is the advantage if you use ~. Is it saving space by not storing the data not required?
0 comentarios
Respuestas (1)
James Tursa
el 17 de Dic. de 2015
Editada: James Tursa
el 17 de Dic. de 2015
It is mainly to avoid cluttering your workspace with variables you don't need in a "neat" manner. E.g.,
[~,I] = max(abs(xc));
does the same thing as:
[M,I] = max(abs(xc));
clear M
In both cases, the first output argument is still calculated and returned by the function. Using ~ simply saves you, the programmer, the trouble of clearing unwanted variables manually (MATLAB will do it for you in the background).
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!