File: getvarfrom.m

package info (click to toggle)
octave-iso2mesh 1.9.8%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 11,128 kB
  • sloc: cpp: 11,982; ansic: 10,158; sh: 365; makefile: 59
file content (33 lines) | stat: -rw-r--r-- 717 bytes parent folder | download | duplicates (2)
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
function p = getvarfrom(ws, name)
%
% p=getvarfrom(ws,name)
%
% get variable value by name from specified work-space
%
% author: Qianqian Fang, <q.fang at neu.edu>
%
% input:
%    ws: name of the work-space, for example, 'base'
%    name: name string of the variable
%
% output:
%    p: the value of the specified variable, if the variable does not
%       exist, return empty array
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%

wsname = ws;
if (~iscell(ws))
    wsname = cell(1);
    wsname{1} = ws;
end

p = [];
for i = 1:length(wsname)
    isdefined = evalin(wsname{i}, ['exist(''' name ''')']);
    if (isdefined == 1)
        p = evalin(wsname{i}, name);
        break
    end
end