File: Status-of-Variables.html

package info (click to toggle)
octave 10.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 145,388 kB
  • sloc: cpp: 335,976; ansic: 82,241; fortran: 20,963; objc: 9,402; sh: 8,756; yacc: 4,392; lex: 4,333; perl: 1,544; java: 1,366; awk: 1,259; makefile: 660; xml: 192
file content (681 lines) | stat: -rw-r--r-- 32,204 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Status of Variables (GNU Octave (version 10.3.0))</title>

<meta name="description" content="Status of Variables (GNU Octave (version 10.3.0))">
<meta name="keywords" content="Status of Variables (GNU Octave (version 10.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Variables.html" rel="up" title="Variables">
<link href="Persistent-Variables.html" rel="prev" title="Persistent Variables">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<div class="section-level-extent" id="Status-of-Variables">
<div class="nav-panel">
<p>
Previous: <a href="Persistent-Variables.html" accesskey="p" rel="prev">Persistent Variables</a>, Up: <a href="Variables.html" accesskey="u" rel="up">Variables</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Status-of-Variables-1"><span>7.3 Status of Variables<a class="copiable-link" href="#Status-of-Variables-1"> &para;</a></span></h3>

<p>When creating simple one-shot programs it can be very convenient to
see which variables are available at the prompt.  The function <code class="code">who</code>
and its siblings <code class="code">whos</code> and <code class="code">whos_line_format</code> will show
different information about what is in memory, as the following shows.
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">str = &quot;A random string&quot;;
who
 -| Variables in the current scope:
 -|
 -| ans  str
</pre></div></div>

<a class="anchor" id="XREFwho"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-who"><span><strong class="def-name">who</strong><a class="copiable-link" href="#index-who"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-who-1"><span><strong class="def-name">who</strong> <code class="def-code-arguments">pattern &hellip;</code><a class="copiable-link" href="#index-who-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-who-2"><span><strong class="def-name">who</strong> <code class="def-code-arguments">option pattern &hellip;</code><a class="copiable-link" href="#index-who-2"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-who-3"><span><code class="def-type">C =</code> <strong class="def-name">who</strong> <code class="def-code-arguments">(&hellip;)</code><a class="copiable-link" href="#index-who-3"> &para;</a></span></dt>
<dd><p>List currently defined variables matching the given patterns.
</p>
<p>Valid pattern syntax is the same as described for the <code class="code">clear</code> command.
If no patterns are supplied, all variables are listed.
</p>
<p>By default, only variables visible in the local scope are displayed.
</p>
<p>The following are valid options, but may not be combined.
</p>
<dl class="table">
<dt><code class="code">global</code></dt>
<dd><p>List variables in the global scope rather than the current scope.
</p>
</dd>
<dt><code class="code">-regexp</code></dt>
<dd><p>The patterns are considered to be regular expressions when matching the
variables to display.  The same pattern syntax accepted by the <code class="code">regexp</code>
function is used.
</p>
</dd>
<dt><code class="code">-file</code></dt>
<dd><p>The next argument is treated as a filename.  All variables found within the
specified file are listed.  No patterns are accepted when reading variables
from a file.
</p></dd>
</dl>

<p>If called as a function, return a cell array of defined variable names
matching the given patterns.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwhos">whos</a>, <a class="ref" href="Global-Variables.html#XREFisglobal">isglobal</a>, <a class="ref" href="Variables.html#XREFisvarname">isvarname</a>, <a class="ref" href="#XREFexist">exist</a>, <a class="ref" href="Searching-and-Replacing-in-Strings.html#XREFregexp">regexp</a>.
</p></dd></dl>


<a class="anchor" id="XREFwhos"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-whos"><span><strong class="def-name">whos</strong><a class="copiable-link" href="#index-whos"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-whos-1"><span><strong class="def-name">whos</strong> <code class="def-code-arguments">pattern &hellip;</code><a class="copiable-link" href="#index-whos-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-whos-2"><span><strong class="def-name">whos</strong> <code class="def-code-arguments">option pattern &hellip;</code><a class="copiable-link" href="#index-whos-2"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-whos-3"><span><code class="def-type">S =</code> <strong class="def-name">whos</strong> <code class="def-code-arguments">(&quot;pattern&quot;, &hellip;)</code><a class="copiable-link" href="#index-whos-3"> &para;</a></span></dt>
<dd><p>Provide detailed information on currently defined variables matching the
given patterns.
</p>
<p>Options and pattern syntax are the same as for the <code class="code">who</code> command.
</p>
<p>Extended information about each variable is summarized in a table with the
following default entries.
</p>
<dl class="table">
<dt>Attr</dt>
<dd><p>Attributes of the listed variable.  Possible attributes are:
</p>
<dl class="table">
<dt>blank</dt>
<dd><p>Variable in local scope
</p>
</dd>
<dt><code class="code">c</code></dt>
<dd><p>Variable of complex type.
</p>
</dd>
<dt><code class="code">f</code></dt>
<dd><p>Formal parameter (function argument).
</p>
</dd>
<dt><code class="code">g</code></dt>
<dd><p>Variable with global scope.
</p>
</dd>
<dt><code class="code">p</code></dt>
<dd><p>Persistent variable.
</p></dd>
</dl>

</dd>
<dt>Name</dt>
<dd><p>The name of the variable.
</p>
</dd>
<dt>Size</dt>
<dd><p>The logical size of the variable.  A scalar is 1x1, a vector is
1xN or Nx1, a 2-D matrix is MxN.
</p>
</dd>
<dt>Bytes</dt>
<dd><p>The amount of memory currently used to store the variable.
</p>
</dd>
<dt>Class</dt>
<dd><p>The class of the variable.  Examples include double, single, char, uint16,
cell, and struct.
</p></dd>
</dl>

<p>The table can be customized to display more or less information through
the function <code class="code">whos_line_format</code>.
</p>
<p>If <code class="code">whos</code> is called as a function, return a struct array of defined
variable names matching the given patterns.  Fields in the structure
describing each variable are: name, size, bytes, class, global, sparse,
complex, nesting, persistent.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwho">who</a>, <a class="ref" href="#XREFwhos_005fline_005fformat">whos_line_format</a>.
</p></dd></dl>


<a class="anchor" id="XREFwhos_005fline_005fformat"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-whos_005fline_005fformat"><span><code class="def-type"><var class="var">val</var> =</code> <strong class="def-name">whos_line_format</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-whos_005fline_005fformat"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-whos_005fline_005fformat-1"><span><code class="def-type"><var class="var">old_val</var> =</code> <strong class="def-name">whos_line_format</strong> <code class="def-code-arguments">(<var class="var">new_val</var>)</code><a class="copiable-link" href="#index-whos_005fline_005fformat-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-whos_005fline_005fformat-2"><span><code class="def-type"><var class="var">old_val</var> =</code> <strong class="def-name">whos_line_format</strong> <code class="def-code-arguments">(<var class="var">new_val</var>, &quot;local&quot;)</code><a class="copiable-link" href="#index-whos_005fline_005fformat-2"> &para;</a></span></dt>
<dd><p>Query or set the format string used by the command <code class="code">whos</code>.
</p>
<p>A full format string is:
</p>
<div class="example smallexample">
<pre class="example-preformatted">%[modifier]&lt;command&gt;[:width[:left-min[:balance]]];
</pre></div>

<p>The following command sequences are available:
</p>
<dl class="table">
<dt><code class="code">%a</code></dt>
<dd><p>Prints attributes of variables (c=complex, s=sparse, f=formal parameter,
g=global, p=persistent).
</p>
</dd>
<dt><code class="code">%b</code></dt>
<dd><p>Prints number of bytes occupied by variables.
</p>
</dd>
<dt><code class="code">%c</code></dt>
<dd><p>Prints class names of variables.
</p>
</dd>
<dt><code class="code">%e</code></dt>
<dd><p>Prints elements held by variables.
</p>
</dd>
<dt><code class="code">%n</code></dt>
<dd><p>Prints variable names.
</p>
</dd>
<dt><code class="code">%s</code></dt>
<dd><p>Prints dimensions of variables.
</p>
</dd>
<dt><code class="code">%t</code></dt>
<dd><p>Prints type names of variables.
</p></dd>
</dl>

<p>Every command may also have an alignment modifier:
</p>
<dl class="table">
<dt><code class="code">l</code></dt>
<dd><p>Left alignment.
</p>
</dd>
<dt><code class="code">r</code></dt>
<dd><p>Right alignment (default).
</p>
</dd>
<dt><code class="code">c</code></dt>
<dd><p>Column-aligned (only applicable to command %s).
</p></dd>
</dl>

<p>The <code class="code">width</code> parameter is a positive integer specifying the minimum
number of columns used for printing.  No maximum is needed as the field will
auto-expand as required.
</p>
<p>The parameters <code class="code">left-min</code> and <code class="code">balance</code> are only available when
the column-aligned modifier is used with the command &lsquo;<samp class="samp">%s</samp>&rsquo;.
<code class="code">balance</code> specifies the column number within the field width which
will be aligned between entries.  Numbering starts from 0 which indicates
the leftmost column.  <code class="code">left-min</code> specifies the minimum field width to
the left of the specified balance column.
</p>
<p>The default format is:
</p>
<div class="example">
<pre class="example-preformatted">&quot;  %la:5; %ln:6; %cs:16:6:1;  %rb:12;  %lc:-1;\n&quot;
</pre></div>

<p>When called from inside a function with the <code class="code">&quot;local&quot;</code> option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwhos">whos</a>.
</p></dd></dl>


<p>Instead of displaying which variables are in memory, it is possible
to determine if a given variable is available.  That way it is possible
to alter the behavior of a program depending on the existence of a
variable.  The following example illustrates this.
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">if (! exist (&quot;meaning&quot;, &quot;var&quot;))
  disp (&quot;The program has no 'meaning'&quot;);
endif
</pre></div></div>

<a class="anchor" id="XREFexist"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-exist"><span><code class="def-type"><var class="var">c</var> =</code> <strong class="def-name">exist</strong> <code class="def-code-arguments">(<var class="var">name</var>)</code><a class="copiable-link" href="#index-exist"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-exist-1"><span><code class="def-type"><var class="var">c</var> =</code> <strong class="def-name">exist</strong> <code class="def-code-arguments">(<var class="var">name</var>, <var class="var">type</var>)</code><a class="copiable-link" href="#index-exist-1"> &para;</a></span></dt>
<dd><p>Check for the existence of <var class="var">name</var> as a variable, function, file, directory,
or class.
</p>
<p>The return code <var class="var">c</var> is one of
</p>
<dl class="table">
<dt>1</dt>
<dd><p><var class="var">name</var> is a variable.
</p>
</dd>
<dt>2</dt>
<dd><p><var class="var">name</var> is an absolute filename, an ordinary file in Octave&rsquo;s <code class="code">path</code>,
or (after appending &lsquo;<samp class="samp">.m</samp>&rsquo;) a function file in Octave&rsquo;s <code class="code">path</code>.
</p>
</dd>
<dt>3</dt>
<dd><p><var class="var">name</var> is a &lsquo;<samp class="samp">.oct</samp>&rsquo; or &lsquo;<samp class="samp">.mex</samp>&rsquo; file in Octave&rsquo;s <code class="code">path</code>.
</p>
</dd>
<dt>5</dt>
<dd><p><var class="var">name</var> is a built-in function.
</p>
</dd>
<dt>7</dt>
<dd><p><var class="var">name</var> is a directory.
</p>
</dd>
<dt>8</dt>
<dd><p><var class="var">name</var> is a classdef class.
</p>
</dd>
<dt>103</dt>
<dd><p><var class="var">name</var> is a function not associated with a file (entered on the command
line).
</p>
</dd>
<dt>0</dt>
<dd><p><var class="var">name</var> does not exist.
</p></dd>
</dl>

<p>If the optional argument <var class="var">type</var> is supplied, check only for symbols of the
specified type.  Valid types are
</p>
<dl class="table">
<dt><code class="code">&quot;var&quot;</code></dt>
<dd><p>Check only for variables.
</p>
</dd>
<dt><code class="code">&quot;builtin&quot;</code></dt>
<dd><p>Check only for built-in functions.
</p>
</dd>
<dt><code class="code">&quot;dir&quot;</code></dt>
<dd><p>Check only for directories.
</p>
</dd>
<dt><code class="code">&quot;file&quot;</code></dt>
<dd><p>Check only for files and directories.
</p>
</dd>
<dt><code class="code">&quot;class&quot;</code></dt>
<dd><p>Check only for classdef classes.
</p></dd>
</dl>

<p>If no type is given, and there are multiple possible matches for name,
<code class="code">exist</code> will return a code according to the following priority list:
variable, built-in function, oct-file, directory, file, class.
</p>
<p><code class="code">exist</code> returns 2 if a regular file called <var class="var">name</var> is present in
Octave&rsquo;s search path.  For information about other types of files not on the
search path use some combination of the functions <code class="code">file_in_path</code> and
<code class="code">stat</code> instead.
</p>
<p>Programming Note: If <var class="var">name</var> is implemented by a buggy .oct/.mex file,
calling <var class="var">exist</var> may cause Octave to crash.  To maintain high performance,
Octave trusts .oct/.mex files instead of sandboxing them.
</p>

<p><strong class="strong">See also:</strong> <a class="ref" href="Manipulating-the-Load-Path.html#XREFfile_005fin_005floadpath">file_in_loadpath</a>, <a class="ref" href="Filesystem-Utilities.html#XREFfile_005fin_005fpath">file_in_path</a>, <a class="ref" href="Manipulating-the-Load-Path.html#XREFdir_005fin_005floadpath">dir_in_loadpath</a>, <a class="ref" href="Filesystem-Utilities.html#XREFstat">stat</a>.
</p></dd></dl>


<p>Usually Octave will manage the memory, but sometimes it can be practical
to remove variables from memory manually.  This is usually needed when
working with large variables that fill a substantial part of the memory.
On a computer that uses the IEEE&nbsp;754 floating point format, the following
program allocates a matrix that requires around 128 MB memory.
</p>
<div class="example">
<pre class="example-preformatted">large_matrix = zeros (4000, 4000);
</pre></div>

<p>Since having this variable in memory might slow down other computations,
it can be necessary to remove it manually from memory.  The <code class="code">clear</code>
or <code class="code">clearvars</code> functions do this.
</p>
<a class="anchor" id="XREFclear"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-clear"><span><strong class="def-name">clear</strong><a class="copiable-link" href="#index-clear"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-clear-1"><span><strong class="def-name">clear</strong> <code class="def-code-arguments"><var class="var">pattern</var> &hellip;</code><a class="copiable-link" href="#index-clear-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-clear-2"><span><strong class="def-name">clear</strong> <code class="def-code-arguments"><var class="var">options</var> <var class="var">pattern</var> &hellip;</code><a class="copiable-link" href="#index-clear-2"> &para;</a></span></dt>
<dd><p>Delete the names matching the given <var class="var">pattern</var>s thereby freeing memory.
</p>
<p>The <var class="var">pattern</var> may contain the following special characters:
</p>
<dl class="table">
<dt><code class="code">?</code></dt>
<dd><p>Match any single character.
</p>
</dd>
<dt><code class="code">*</code></dt>
<dd><p>Match zero or more characters.
</p>
</dd>
<dt><code class="code">[ <var class="var">list</var> ]</code></dt>
<dd><p>Match the list of characters specified by <var class="var">list</var>.  If the first character
is <code class="code">!</code> or <code class="code">^</code>, match all characters except those specified by
<var class="var">list</var>.  For example, the pattern <code class="code">[a-zA-Z]</code> will match all lowercase
and uppercase alphabetic characters.  On Windows, square brackets are matched
literally and are not used to group characters.
</p></dd>
</dl>

<p>For example, the command
</p>
<div class="example">
<pre class="example-preformatted">clear foo b*r
</pre></div>

<p>clears the name <code class="code">foo</code> and all names that begin with the letter &lsquo;<samp class="samp">b</samp>&rsquo;
and end with the letter &lsquo;<samp class="samp">r</samp>&rsquo;.
</p>
<p>If <code class="code">clear</code> is called without any arguments, all user-defined variables
are cleared from the current workspace (i.e., local variables).  Any global
variables present will no longer be visible in the current workspace, but they
will continue to exist in the global workspace.  Functions are unaffected by
this form of <code class="code">clear</code>.
</p>
<p>The following options are available in both long and short form
</p>
<dl class="table">
<dt><code class="code">all, -all, -a</code></dt>
<dd><p>Clear all local and global user-defined variables, and all functions from the
symbol table.
</p>
</dd>
<dt><code class="code">-exclusive, -x</code></dt>
<dd><p>Clear variables that do <strong class="strong">not</strong> match the following pattern.
</p>
</dd>
<dt><code class="code">functions, -functions, -f</code></dt>
<dd><p>Clear function names from the function symbol table.  Persistent variables
will be re-initialized to their default value unless the function has been
locked in memory with <code class="code">mlock</code>.
</p>
</dd>
<dt><code class="code">global, -global, -g</code></dt>
<dd><p>Clear global variable names.
</p>
</dd>
<dt><code class="code">variables, -variables, -v</code></dt>
<dd><p>Clear local variable names.
</p>
</dd>
<dt><code class="code">classes, -classes, -c</code></dt>
<dd><p>Clear the class structure table and all objects.
</p>
</dd>
<dt><code class="code">-regexp, -r</code></dt>
<dd><p>The <var class="var">pattern</var> arguments are treated as regular expressions and any matches
will be cleared.
</p></dd>
</dl>

<p>With the exception of <samp class="option">-exclusive</samp> and <samp class="option">-regexp</samp>, all long
options can be used without the dash as well.  Note that, aside from
<samp class="option">-exclusive</samp>, only one other option may appear.  All options must
appear before any patterns.
</p>
<p>Programming Notes: The command <code class="code">clear <var class="var">name</var></code> only clears the variable
<var class="var">name</var> when both a variable and a (shadowed) function named <var class="var">name</var>
are currently defined.  For example, suppose you have defined a function
<code class="code">foo</code>, and then hidden it by performing the assignment <code class="code">foo = 2</code>.
Executing the command <code class="code">clear foo</code> once will clear the variable
definition and restore the definition of <code class="code">foo</code> as a function.
Executing <code class="code">clear foo</code> a second time will clear the function definition.
</p>
<p>When a local variable name, which is linked to a global variable, is cleared
only the local copy of the variable is removed.  The global copy is untouched
and can be restored with <code class="code">global <var class="var">global_varname</var></code>.  Conversely,
<code class="code">clear -g <var class="var">global_varname</var></code> will remove both the local and global
variables.
</p>

<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFclearvars">clearvars</a>, <a class="ref" href="#XREFwho">who</a>, <a class="ref" href="#XREFwhos">whos</a>, <a class="ref" href="#XREFexist">exist</a>, <a class="ref" href="Function-Locking.html#XREFmlock">mlock</a>.
</p></dd></dl>


<a class="anchor" id="XREFclearvars"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-clearvars"><span><strong class="def-name">clearvars</strong><a class="copiable-link" href="#index-clearvars"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-clearvars-1"><span><strong class="def-name">clearvars</strong> <code class="def-code-arguments"><var class="var">pattern</var> &hellip;</code><a class="copiable-link" href="#index-clearvars-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-clearvars-2"><span><strong class="def-name">clearvars</strong> <code class="def-code-arguments">-regexp <var class="var">pattern</var> &hellip;</code><a class="copiable-link" href="#index-clearvars-2"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-clearvars-3"><span><strong class="def-name">clearvars</strong> <code class="def-code-arguments">&hellip; -except <var class="var">pattern</var> &hellip;</code><a class="copiable-link" href="#index-clearvars-3"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-clearvars-4"><span><strong class="def-name">clearvars</strong> <code class="def-code-arguments">&hellip; -except -regexp <var class="var">pattern</var> &hellip;</code><a class="copiable-link" href="#index-clearvars-4"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-clearvars-5"><span><strong class="def-name">clearvars</strong> <code class="def-code-arguments">-global &hellip;</code><a class="copiable-link" href="#index-clearvars-5"> &para;</a></span></dt>
<dd><p>Delete the variables matching the given <var class="var">pattern</var>s from memory.
</p>
<p>The <var class="var">pattern</var> may contain the following special characters:
</p>
<dl class="table">
<dt><code class="code">?</code></dt>
<dd><p>Match any single character.
</p>
</dd>
<dt><code class="code">*</code></dt>
<dd><p>Match zero or more characters.
</p>
</dd>
<dt><code class="code">[ <var class="var">list</var> ]</code></dt>
<dd><p>Match the list of characters specified by <var class="var">list</var>.  If the first
character is <code class="code">!</code> or <code class="code">^</code>, match all characters except those
specified by <var class="var">list</var>.  For example, the pattern <code class="code">[a-zA-Z]</code> will
match all lowercase and uppercase alphabetic characters.
</p></dd>
</dl>

<p>If the <samp class="option">-regexp</samp> option is given then subsequent patterns are treated
as regular expressions and any matches will be cleared.
</p>
<p>If the <samp class="option">-except</samp> option is given then subsequent patterns select
variables that will <strong class="strong">not</strong> be cleared.
</p>
<p>If the <samp class="option">-global</samp> option is given then all patterns will be applied
to global variables rather than local variables.
</p>
<p>When called with no arguments, <code class="code">clearvars</code> deletes all local variables.
</p>
<p>Example Code:
</p>
<p>Clear all variables starting with <code class="code">'x'</code> and the specific variable
<code class="code">&quot;foobar&quot;</code>
</p>
<div class="example">
<pre class="example-preformatted">clearvars x* foobar
</pre></div>

<p>Clear the specific variable <code class="code">&quot;foobar&quot;</code> and use regular expressions to
clear all variables starting with <code class="code">'x'</code> or <code class="code">'y'</code>.
</p>
<div class="example">
<pre class="example-preformatted">clearvars foobar -regexp ^x ^y
</pre></div>

<p>Clear all variables except for <code class="code">&quot;foobar&quot;</code>
</p>
<div class="example">
<pre class="example-preformatted">clearvars -except foobar
</pre></div>

<p>Clear all variables beginning with <code class="code">&quot;foo&quot;</code>, except for those ending
in <code class="code">&quot;bar&quot;</code>
</p>
<div class="example">
<pre class="example-preformatted">clearvars foo* -except -regexp bar$
</pre></div>


<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFclear">clear</a>, <a class="ref" href="#XREFwho">who</a>, <a class="ref" href="#XREFwhos">whos</a>, <a class="ref" href="#XREFexist">exist</a>.
</p></dd></dl>


<a class="anchor" id="XREFpack"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-pack"><span><strong class="def-name">pack</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-pack"> &para;</a></span></dt>
<dd><p>Consolidate workspace memory in <small class="sc">MATLAB</small>.
</p>
<p>This function is provided for compatibility, but does nothing in Octave.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFclear">clear</a>.
</p></dd></dl>


<p>Information about a function or variable such as its location in the
file system can also be acquired from within Octave.  This is usually
only useful during development of programs, and not within a program.
</p>
<a class="anchor" id="XREFtype"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-type"><span><strong class="def-name">type</strong> <code class="def-code-arguments"><var class="var">name</var> &hellip;</code><a class="copiable-link" href="#index-type"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-type-1"><span><strong class="def-name">type</strong> <code class="def-code-arguments">-q <var class="var">name</var> &hellip;</code><a class="copiable-link" href="#index-type-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-type-2"><span><code class="def-type">text =</code> <strong class="def-name">type</strong> <code class="def-code-arguments">(&quot;<var class="var">name</var>&quot;, &hellip;)</code><a class="copiable-link" href="#index-type-2"> &para;</a></span></dt>
<dd><p>Display the contents of <var class="var">name</var> which may be a file, function (m-file),
variable, operator, or keyword.
</p>
<p><code class="code">type</code> normally prepends a header line describing the category of
<var class="var">name</var> such as function or variable; The <samp class="option">-q</samp> option suppresses
this behavior.
</p>
<p>If no output variable is used the contents are displayed on screen.
Otherwise, a cell array of strings is returned, where each element
corresponds to the contents of each requested function.
</p></dd></dl>


<a class="anchor" id="XREFwhich"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-which"><span><strong class="def-name">which</strong> <code class="def-code-arguments"><var class="var">name</var> &hellip;</code><a class="copiable-link" href="#index-which"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-which-1"><span><code class="def-type">[<var class="var">str</var>, &hellip;] =</code> <strong class="def-name">which</strong> <code class="def-code-arguments">('<var class="var">name</var>', &hellip;)</code><a class="copiable-link" href="#index-which-1"> &para;</a></span></dt>
<dd><p>Display the type of each <var class="var">name</var>.
</p>
<p>If <var class="var">name</var> is defined from a function file, the full name of the file is
also displayed.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Getting-Help.html#XREFhelp">help</a>, <a class="ref" href="Getting-Help.html#XREFlookfor">lookfor</a>.
</p></dd></dl>


<a class="anchor" id="XREFwhat"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-what"><span><strong class="def-name">what</strong><a class="copiable-link" href="#index-what"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-what-1"><span><strong class="def-name">what</strong> <code class="def-code-arguments"><var class="var">dir</var></code><a class="copiable-link" href="#index-what-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-what-2"><span><code class="def-type">w =</code> <strong class="def-name">what</strong> <code class="def-code-arguments">(<var class="var">dir</var>)</code><a class="copiable-link" href="#index-what-2"> &para;</a></span></dt>
<dd><p>List the Octave specific files in directory <var class="var">dir</var>.
</p>
<p>If <var class="var">dir</var> is not specified then the current directory is used.
</p>
<p>If a return argument is requested, the files found are returned in the
structure <var class="var">w</var>.  The structure contains the following fields:
</p>
<dl class="table">
<dt>path</dt>
<dd><p>Full path to directory <var class="var">dir</var>
</p>
</dd>
<dt>m</dt>
<dd><p>Cell array of m-files
</p>
</dd>
<dt>mat</dt>
<dd><p>Cell array of mat files
</p>
</dd>
<dt>mex</dt>
<dd><p>Cell array of mex files
</p>
</dd>
<dt>oct</dt>
<dd><p>Cell array of oct files
</p>
</dd>
<dt>mdl</dt>
<dd><p>Cell array of mdl files
</p>
</dd>
<dt>slx</dt>
<dd><p>Cell array of slx files
</p>
</dd>
<dt>p</dt>
<dd><p>Cell array of p-files
</p>
</dd>
<dt>classes</dt>
<dd><p>Cell array of class directories (<samp class="file">@<var class="var">classname</var>/</samp>)
</p>
</dd>
<dt>packages</dt>
<dd><p>Cell array of package directories (<samp class="file">+<var class="var">pkgname</var>/</samp>)
</p></dd>
</dl>

<p>Compatibility Note: Octave does not support mdl, slx, and p files.
<code class="code">what</code> will always return an empty list for these categories.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFwhich">which</a>, <a class="ref" href="Current-Working-Directory.html#XREFls">ls</a>, <a class="ref" href="#XREFexist">exist</a>.
</p></dd></dl>



</div>
<hr>
<div class="nav-panel">
<p>
Previous: <a href="Persistent-Variables.html">Persistent Variables</a>, Up: <a href="Variables.html">Variables</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>