Mihai Sprinceana
Un forum de programare cu de toate. Va astept sa va inscrieti si sa deveniti moderatori. Oricine este binevenit aici sa se inscrie si sa aiba acces la informatie free! Fiecare este liber sa adauge proiecte programe free etc. Ajutati acest forum sa devina o comunitate puternica unde fiecare invata de la fiecare! Tot ce trebuie sa faceti este sa va inregistrati si fiecare contributie se poate dovedi utila in timp! Forumul este free informatia free dk aveti timp liber ajutati si pe ceilalti si invatati si voi in acelasi timp! Haideti sa facem ceva pt.a ne ajuta intre noi!
Cititi regulament postare forum inainte de a posta!
|
Lista Forumurilor Pe Tematici
|
Mihai Sprinceana | Inregistrare | Login
POZE MIHAI SPRINCEANA
Nu sunteti logat.
|
Nou pe simpatie: Mayyy la Simpatie.ro
| Femeie 23 ani Brasov cauta Barbat 23 - 60 ani |
|
mihaispr
Administrator
Inregistrat: acum 17 ani
Postari: 2142
|
|
Variabilele de tip persistent sunt variabilele locale declarate si folosite de anumite functii si subfunctii din fisierul matlab(.m).
Sintaxa generala:
persistent nume_variabila1,nume_variabila2.....nume_variabila n
Ex: persistent a,b %definirea a 2 variabile locale in matlab
Din documentatia softului matlab:
>>doc persistent
persistent
Define persistent variable
Syntax
persistent X Y Z
Description
persistent X Y Z defines X, Y, and Z as variables that are local to the function in which they are declared; yet their values are retained in memory between calls to the function. Persistent variables are similar to global variables because MATLAB creates permanent storage for both. They differ from global variables in that persistent variables are known only to the function in which they are declared. This prevents persistent variables from being changed by other functions or from the MATLAB command line.
Persistent variables are cleared when the M-file is cleared from memory or when the M-file is changed. To keep an M-file in memory until MATLAB quits, use mlock.
If the persistent variable does not exist the first time you issue the persistent statement, it is initialized to the empty matrix.
It is an error to declare a variable persistent if a variable with the same name exists in the current workspace.
Remarks
There is no function form of the persistent command (i.e., you cannot use parentheses and quote the variable names).
Example
This function prompts a user to enter a directory name to use in locating one or more files. If the user has already entered this information, and it requires no modification, they do not need to enter it again. This is because the function stores it in a persistent variable (lastDir), and offers it as the default selection. Here is the function definition: function find_file(file) persistent lastDir if isempty(lastDir) prompt = 'Enter directory: '; else prompt = ['Enter directory[' lastDir ']: ']; end response = input(prompt, 's'); if ~isempty(response) dirName = response; else dirName = lastDir; end dir(strcat(dirName, file)) lastDir = dirName;
Execute the function twice. The first time, it prompts you to enter the information and does not offer a default: cd(matlabroot)
find_file('is*.m') Enter directory: toolbox/matlab/strfun/
iscellstr.m ischar.m isletter.m isspace.m isstr.m isstrprop.m
The second time, it does offer a default taken from the persistent variable dirName: find_file('is*.m') Enter directory[toolbox/matlab/strfun/]: toolbox/matlab/elmat/
isempty.m isfinite.m isscalar.m isequal.m isinf.m isvector.m isequalwithequalnans.m isnan.m
Pentru a edita unul din fisierele .m de mai sus tastati in command window:
>>edit nume
Ex: >>edit isempty
s.a.m.d
|
|
pus acum 15 ani |
|