<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235614</link>
    <title>MATLAB Central Newsreader - Using workspace variable in m-file</title>
    <description>Feed for thread: Using workspace variable in m-file</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 06 Sep 2008 06:33:02 -0400</pubDate>
      <title>Using workspace variable in m-file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235614#598985</link>
      <author>jay kumar</author>
      <description>Hi,&lt;br&gt;
I want to use workspace variables in my m-file and i want to do some operation on that variables in m-file. but that variables and their values are available in workspace.&lt;br&gt;
&lt;br&gt;
e.g I want to multiply two transfer functions and obtain bode plot for different values of parameters but that two transfer functions are available in workspace &lt;br&gt;
&lt;br&gt;
I do not want to write transfer functions again in m-file. Instead of that i want to obtain it from workspace.</description>
    </item>
    <item>
      <pubDate>Sat, 06 Sep 2008 07:47:01 -0400</pubDate>
      <title>Re: Using workspace variable in m-file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235614#598990</link>
      <author>Bruno Luong</author>
      <description>&quot;jay kumar&quot; &amp;lt;kumar.jay.123@gmail.com&amp;gt; wrote in message &amp;lt;g9t86u$cu5$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I want to use workspace variables in my m-file and i want to do some operation on that variables in m-file. but that variables and their values are available in workspace.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; e.g I want to multiply two transfer functions and obtain bode plot for different values of parameters but that two transfer functions are available in workspace &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I do not want to write transfer functions again in m-file. Instead of that i want to obtain it from workspace.&lt;br&gt;
&lt;br&gt;
What's wrong with passing the value of those variables (could be function handle of the transfer functions) into your m file???&lt;br&gt;
&lt;br&gt;
The mechanism of input and output for functions is designed so that direct messing between workspace is minimal.&lt;br&gt;
&lt;br&gt;
But if you insist, there is EVALIN for that.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Sat, 06 Sep 2008 07:56:01 -0400</pubDate>
      <title>Re: Using workspace variable in m-file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235614#598993</link>
      <author>Husam Aldahiyat</author>
      <description>Use global. Solves all life's problems.</description>
    </item>
    <item>
      <pubDate>Sat, 06 Sep 2008 08:51:02 -0400</pubDate>
      <title>Re: Using workspace variable in m-file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235614#598999</link>
      <author>John D'Errico</author>
      <description>&quot;Husam Aldahiyat&quot; &amp;lt;numandina@gmail.com&amp;gt; wrote in message &amp;lt;g9td2h$se1$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Use global. Solves all life's problems.&lt;br&gt;
&lt;br&gt;
Yes, and it creates other problems. Globals&lt;br&gt;
are sloppy, lazy programming.&lt;br&gt;
&lt;br&gt;
Pass the variables in. If they are functions,&lt;br&gt;
perhaps anonymous functions, or simply&lt;br&gt;
variables, then it is far simpler to pass them&lt;br&gt;
in as arguments to the function. This solves&lt;br&gt;
the OP's problems without creating other&lt;br&gt;
ones.&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Sat, 06 Sep 2008 14:01:46 -0400</pubDate>
      <title>Re: Using workspace variable in m-file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235614#599031</link>
      <author>Andrew</author>
      <description>On Sep 6, 12:33 am, &quot;jay kumar&quot; &amp;lt;kumar.jay....@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I want to use workspace variables in my m-file and i want to do some operation on that variables in m-file. but that variables and their values are available in workspace.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; e.g I want to multiply two transfer functions and obtain bode plot for different values of parameters but that two transfer functions are available in workspace&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I do not want to write transfer functions again in m-file. Instead of that i want to obtain it from workspace.&lt;br&gt;
&lt;br&gt;
If you define the transfer functions in the workspace (from the&lt;br&gt;
command page, I assume), then they are already in the workspace.  The&lt;br&gt;
m-file will already see the variable, unless you begin your m-files as&lt;br&gt;
I do with clear all; close all commands.  Once the variables are in&lt;br&gt;
the workspace, the m-file will automatically recognize them.</description>
    </item>
    <item>
      <pubDate>Sat, 06 Sep 2008 14:42:01 -0400</pubDate>
      <title>Re: Using workspace variable in m-file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235614#599032</link>
      <author>John D'Errico</author>
      <description>Andrew &amp;lt;andrewkgentile@gmail.com&amp;gt; wrote in message &amp;lt;33eac32d-6e15-4ff2-895f-f04ec68458d0@d1g2000hsg.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; On Sep 6, 12:33 am, &quot;jay kumar&quot; &amp;lt;kumar.jay....@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt; I want to use workspace variables in my m-file and i want to do some operation on that variables in m-file. but that variables and their values are available in workspace.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; e.g I want to multiply two transfer functions and obtain bode plot for different values of parameters but that two transfer functions are available in workspace&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I do not want to write transfer functions again in m-file. Instead of that i want to obtain it from workspace.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you define the transfer functions in the workspace (from the&lt;br&gt;
&amp;gt; command page, I assume), then they are already in the workspace.  The&lt;br&gt;
&amp;gt; m-file will already see the variable, unless you begin your m-files as&lt;br&gt;
&amp;gt; I do with clear all; close all commands.  Once the variables are in&lt;br&gt;
&amp;gt; the workspace, the m-file will automatically recognize them.&lt;br&gt;
&lt;br&gt;
This is only true if the m-file is a script.&lt;br&gt;
&lt;br&gt;
Scripts are generally a poor choice, especially &lt;br&gt;
if you begin them with clear commands.&lt;br&gt;
&lt;br&gt;
Far better is to learn to use and write functions.&lt;br&gt;
Functions have their own workspace, so you&lt;br&gt;
need not worry about polluting the base&lt;br&gt;
workspace with the odd variables created inside&lt;br&gt;
your functions. This is a far cleaner way to&lt;br&gt;
build your tools. Make small functions that do&lt;br&gt;
a single thing. In some languages these are&lt;br&gt;
called idioms. Build up an idiom library of your&lt;br&gt;
own, formed both from the functions you have&lt;br&gt;
written to solve your own specific type of&lt;br&gt;
problems, and from those useful utilities that&lt;br&gt;
you have downloaded from the file exchange.&lt;br&gt;
&lt;br&gt;
You will be surprised how fast these functions&lt;br&gt;
accumulate, as well as how useful they will be.&lt;br&gt;
Before long, other people you work with will&lt;br&gt;
find out about your collection of idioms.&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Sun, 07 Sep 2008 13:53:33 -0400</pubDate>
      <title>Re: Using workspace variable in m-file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235614#599118</link>
      <author>Andrew</author>
      <description>On Sep 6, 8:42 am, &quot;John D'Errico&quot; &amp;lt;woodch...@rochester.rr.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Andrew &amp;lt;andrewkgent...@gmail.com&amp;gt; wrote in message &amp;lt;33eac32d-6e15-4ff2-895f-f04ec6845...@d1g2000hsg.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; On Sep 6, 12:33 am, &quot;jay kumar&quot; &amp;lt;kumar.jay....@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I want to use workspace variables in my m-file and i want to do some operation on that variables in m-file. but that variables and their values are available in workspace.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; e.g I want to multiply two transfer functions and obtain bode plot for different values of parameters but that two transfer functions are available in workspace&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I do not want to write transfer functions again in m-file. Instead of that i want to obtain it from workspace.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; If you define the transfer functions in the workspace (from the&lt;br&gt;
&amp;gt; &amp;gt; command page, I assume), then they are already in the workspace.  The&lt;br&gt;
&amp;gt; &amp;gt; m-file will already see the variable, unless you begin your m-files as&lt;br&gt;
&amp;gt; &amp;gt; I do with clear all; close all commands.  Once the variables are in&lt;br&gt;
&amp;gt; &amp;gt; the workspace, the m-file will automatically recognize them.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; This is only true if the m-file is a script.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Scripts are generally a poor choice, especially&lt;br&gt;
&amp;gt; if you begin them with clear commands.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Far better is to learn to use and write functions.&lt;br&gt;
&amp;gt; Functions have their own workspace, so you&lt;br&gt;
&amp;gt; need not worry about polluting the base&lt;br&gt;
&amp;gt; workspace with the odd variables created inside&lt;br&gt;
&amp;gt; your functions. This is a far cleaner way to&lt;br&gt;
&amp;gt; build your tools. Make small functions that do&lt;br&gt;
&amp;gt; a single thing. In some languages these are&lt;br&gt;
&amp;gt; called idioms. Build up an idiom library of your&lt;br&gt;
&amp;gt; own, formed both from the functions you have&lt;br&gt;
&amp;gt; written to solve your own specific type of&lt;br&gt;
&amp;gt; problems, and from those useful utilities that&lt;br&gt;
&amp;gt; you have downloaded from the file exchange.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; You will be surprised how fast these functions&lt;br&gt;
&amp;gt; accumulate, as well as how useful they will be.&lt;br&gt;
&amp;gt; Before long, other people you work with will&lt;br&gt;
&amp;gt; find out about your collection of idioms.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; John&lt;br&gt;
&lt;br&gt;
John,&lt;br&gt;
I have been using m-files (as scripts) and functions for about a&lt;br&gt;
decade, and I have never considered the benefit of writing my scripts&lt;br&gt;
as functions.&lt;br&gt;
Thanks for the tip.  I will consider it.&lt;br&gt;
&lt;br&gt;
Andy</description>
    </item>
    <item>
      <pubDate>Sun, 07 Sep 2008 14:12:48 -0400</pubDate>
      <title>Re: Using workspace variable in m-file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235614#599120</link>
      <author>ImageAnalyst</author>
      <description>On Sep 6, 4:51=A0am, &quot;John D'Errico&quot; &amp;lt;woodch...@rochester.rr.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &quot;Husam Aldahiyat&quot; &amp;lt;numand...@gmail.com&amp;gt; wrote in message &amp;lt;g9td2h$se...@fr=&lt;br&gt;
ed.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Use global. Solves all life's problems.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Yes, and it creates other problems. Globals&lt;br&gt;
&amp;gt; are sloppy, lazy programming.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Pass the variables in. If they are functions,&lt;br&gt;
&amp;gt; perhaps anonymous functions, or simply&lt;br&gt;
&amp;gt; variables, then it is far simpler to pass them&lt;br&gt;
&amp;gt; in as arguments to the function. This solves&lt;br&gt;
&amp;gt; the OP's problems without creating other&lt;br&gt;
&amp;gt; ones.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; John&lt;br&gt;
&lt;br&gt;
-------------------------------------------&lt;br&gt;
John:&lt;br&gt;
What if the function is the callback of a button (placed with GUIDE)?&lt;br&gt;
How do you pass variables into that?  GUIDE automatically puts in 3&lt;br&gt;
arguments.  How can you get in other variables that may be needed&lt;br&gt;
inside that function?  I've just been using &quot;global&quot; because I don't&lt;br&gt;
know any other way to get stuff in there.  For a simple example, let's&lt;br&gt;
say the button should multiply a vector by 2 and plot in in an axes.&lt;br&gt;
How do you get that vector into the callback function of the button?&lt;br&gt;
Thanks,&lt;br&gt;
ImageAnalyst&lt;br&gt;
-----------------------------------------------------------</description>
    </item>
    <item>
      <pubDate>Mon, 08 Sep 2008 02:33:40 -0400</pubDate>
      <title>Re: Using workspace variable in m-file</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/235614#599182</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;ImageAnalyst&quot; &amp;lt;imageanalyst@mailinator.com&amp;gt; wrote in message &lt;br&gt;
news:51dfc6c1-996a-4a79-a957-218aca2d1ad9@d77g2000hsb.googlegroups.com...&lt;br&gt;
&amp;gt; On Sep 6, 4:51 am, &quot;John D'Errico&quot; &amp;lt;woodch...@rochester.rr.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; &quot;Husam Aldahiyat&quot; &amp;lt;numand...@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt; &amp;gt; &amp;lt;g9td2h$se...@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Use global. Solves all life's problems.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Yes, and it creates other problems. Globals&lt;br&gt;
&amp;gt; &amp;gt; are sloppy, lazy programming.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Pass the variables in. If they are functions,&lt;br&gt;
&amp;gt; &amp;gt; perhaps anonymous functions, or simply&lt;br&gt;
&amp;gt; &amp;gt; variables, then it is far simpler to pass them&lt;br&gt;
&amp;gt; &amp;gt; in as arguments to the function. This solves&lt;br&gt;
&amp;gt; &amp;gt; the OP's problems without creating other&lt;br&gt;
&amp;gt; &amp;gt; ones.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; John&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; -------------------------------------------&lt;br&gt;
&amp;gt; John:&lt;br&gt;
&amp;gt; What if the function is the callback of a button (placed with GUIDE)?&lt;br&gt;
&amp;gt; How do you pass variables into that?  GUIDE automatically puts in 3&lt;br&gt;
&amp;gt; arguments.  How can you get in other variables that may be needed&lt;br&gt;
&amp;gt; inside that function?  I've just been using &quot;global&quot; because I don't&lt;br&gt;
&amp;gt; know any other way to get stuff in there.  For a simple example, let's&lt;br&gt;
&amp;gt; say the button should multiply a vector by 2 and plot in in an axes.&lt;br&gt;
&amp;gt; How do you get that vector into the callback function of the button?&lt;br&gt;
&lt;br&gt;
In this case, you can't pass variables into the callback directly, but there &lt;br&gt;
are better ways to handle that situation than using globals -- the usual &lt;br&gt;
suspects are storing values in the UserData or the handles structure and &lt;br&gt;
retrieving them inside the callback function, writing your callback as a &lt;br&gt;
nested functions, using SETAPPDATA/GETAPPDATA, etc.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com </description>
    </item>
  </channel>
</rss>

