[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Checking existance of global variable in function?
From: |
Etienne Grossmann |
Subject: |
Re: Checking existance of global variable in function? |
Date: |
Sun, 16 Jul 2006 10:16:24 -0400 |
User-agent: |
Mutt/1.4.2.1i |
Hi Volker,
what about testing whether graphdir is a string, as in:
function [out] = plotinit (eps, file, gnuplotfile)
global graphdir
if (exist('graphdir') ~= 0)
if ~ischar(graphdir), graphdir = ''; end
graphdir=[graphdir '']
Hth,
Etienne
PS: You are appending an empty string to graphdir?
On Sun, Jul 16, 2006 at 08:10:21PM +1200, Volker Kuhlmann wrote:
# I'm trying to check a global variable inside a function file. This
# construction:
#
# function [out] = plotinit (eps, file, gnuplotfile)
# global graphdir
# if (exist('graphdir') ~= 0)
# graphdir=[graphdir '']
#
# produces
# warning: implicit conversion from matrix to string
# on the first access to graphdir. exist() always returns 1, caused by the
# global declaration in the function file. Obviously this global
# declaration can't be removed, but I don't see a way to test inside a
# function whether a global variable has been set, without causing a
# warning.
#
# Is this a bug, meant to be impossible, or am I thick?
#
# GNU Octave, version 2.1.72 (x86_64-suse-linux).
#
# Thanks,
#
# Volker
#
# --
# Volker Kuhlmann is list0570 with the domain in header
# http://volker.dnsalias.net/ Please do not CC list postings to me.
--
Etienne Grossmann ------ http://www.cs.uky.edu/~etienne