matlab - changing values of a global variable via command window -


suppose had global variable g in function f, say. output of f dependent on g, , g declared global within f.

i f work follows through command window:

  • set g value
  • run f, giving result dependent on g
  • set different value of g
  • run f again, giving answer dependent on new g

however, has following problem: involve defining g first, declaring global when f run, results in matlab warning require global variable g not direct input f.

any work around this, or if method fundamentally flawed, alternative appreciated.

yes can this. simple example:

in command window, enter global g , g=2.

then make simple function, e.g.:

function incg global g g=g*2; disp(g) 

run incg command window , see happens. can modify value of g in command window in between executing incg. have careful g exists , has correct value when run incg.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -