inputname and function(cell{:})

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

inputname and function(cell{:})

Lukas Reichlin-4
Dear Octave Community

I'm preparing multiplot-capable plotting functions for the control package. I ran into a problem which boils down to the code in the attached example. I'd like to get the inputnames of all arguments of a function "testfun".

Currently, with

        ret1 = testfun (arg1, arg2, arg3)

nargin is 3 and inputname ranges from 1 to 3.
But with

        ret2 = testfun (args{:})

nargin is still 3 but only inputname(1) exists while inputname(2) and inputname(3) give errors. Therefore I must find an alternative to inputname or an alternative to nargin which counts input arguments the same way as inputname does. Do you know how to circumvent this problem?

Thanks for any help and best regards,
Lukas




------------------------------------------------------------------------------
Got visibility?
Most devs has no idea what their production app looks like.
Find out how fast your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219671;13503038;y?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev

example.m (337 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: inputname and function(cell{:})

Jordi Gutiérrez Hermoso-2
On 14 September 2012 09:30, Lukas Reichlin
<[hidden email]> wrote:

> Currently, with
>
>         ret1 = testfun (arg1, arg2, arg3)
>
> nargin is 3 and inputname ranges from 1 to 3.
> But with
>
>         ret2 = testfun (args{:})
>
> nargin is still 3 but only inputname(1) exists while inputname(2)
> and inputname(3) give errors.

But if you're passing a cs-list, the cs-list itself doesn't have the
variable names that you want, and inputname is working as documented,
returning an empty string.

> Therefore I must find an alternative to inputname or an alternative
> to nargin which counts input arguments the same way as inputname
> does. Do you know how to circumvent this problem?

What exactly is your actual problem? nargin still counts arguments,
but why do you want to know what the variables are called in the
calling function? The calling function doesn't have this information
when you use a cs-list. To me this seems like premature closure or an
X-Y problem:

    http://www.perlmonks.org/index.pl?node_id=542341

Can you give broader context in order to be able to give you a better
answer? There may be a completely differenty way to solve your broader
problem.

- Jordi G. H.

------------------------------------------------------------------------------
Got visibility?
Most devs has no idea what their production app looks like.
Find out how fast your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219671;13503038;y?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev
Reply | Threaded
Open this post in threaded view
|

Re: inputname and function(cell{:})

Lukas Reichlin-4
On 14.09.2012, at 15:46, Jordi Gutiérrez Hermoso <[hidden email]> wrote:

> On 14 September 2012 09:30, Lukas Reichlin
> <[hidden email]> wrote:
>> Currently, with
>>
>>        ret1 = testfun (arg1, arg2, arg3)
>>
>> nargin is 3 and inputname ranges from 1 to 3.
>> But with
>>
>>        ret2 = testfun (args{:})
>>
>> nargin is still 3 but only inputname(1) exists while inputname(2)
>> and inputname(3) give errors.
>
> But if you're passing a cs-list, the cs-list itself doesn't have the
> variable names that you want, and inputname is working as documented,
> returning an empty string.
>
>> Therefore I must find an alternative to inputname or an alternative
>> to nargin which counts input arguments the same way as inputname
>> does. Do you know how to circumvent this problem?
>
> What exactly is your actual problem? nargin still counts arguments,
> but why do you want to know what the variables are called in the
> calling function? The calling function doesn't have this information
> when you use a cs-list. To me this seems like premature closure or an
> X-Y problem:
>
>    http://www.perlmonks.org/index.pl?node_id=542341
>
> Can you give broader context in order to be able to give you a better
> answer? There may be a completely differenty way to solve your broader
> problem.
>
> - Jordi G. H.

Hi Jordi

Thanks for your quick reply! The broader context is given on line 92 of MDSSystem2.m [1]

        bode (G_per{:}, w)

G_per is a cell of LTI models to be plotted by bode. The bode function generates an automatic legend with the argument names given by the inputname function. On line 91 in bode.m [2]

        legend_args{k} = inputname(sys_idx(k));  # watch out for bode (lticell{:})

I'm trying to get the argument names. However, only inputname(1) and inputname(2) work because bode (G_per{:}, w) has only two arguments. But since G_per contains about a dozen LTI systems, nargin = numel (G_per) + 1 (+1 because of argument w). Here inputname(n) for n>2 is failing. Therefore I need a way to find out how many inputnames were given (nargin doesn't work) so I can stop before inputname(n) fails. (counting the inputs like inputname, instead of a try-catch block)

Best regards,
Lukas


[1] MDSSystem2.m
http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/main/control/devel/MDSSystem2.m?revision=11015&view=markup


[2] bode.m
http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/main/control/inst/bode.m?revision=11025&view=markup




------------------------------------------------------------------------------
How fast is your code?
3 out of 4 devs don\\\'t know how their code performs in production.
Find out how slow your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219672;13503038;z?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev
Reply | Threaded
Open this post in threaded view
|

Re: inputname and function(cell{:})

Jordi Gutiérrez Hermoso-2
Lukas,

This is just off the top of my head and I didn't look at your code in
detail, but how about using a struct instead of a cell to pass the
arguments and getting the names of the variables with the fieldnames
function?

HTH,
- Jordi G. H.

------------------------------------------------------------------------------
How fast is your code?
3 out of 4 devs don\\\'t know how their code performs in production.
Find out how slow your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219672;13503038;z?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev
Reply | Threaded
Open this post in threaded view
|

Re: inputname and function(cell{:})

Lukas Reichlin-4
On 15.09.2012, at 16:52, Jordi Gutiérrez Hermoso <[hidden email]> wrote:

> Lukas,
>
> This is just off the top of my head and I didn't look at your code in
> detail, but how about using a struct instead of a cell to pass the
> arguments and getting the names of the variables with the fieldnames
> function?
>
> HTH,
> - Jordi G. H.

Hi Jordi

Hmm, I was looking for a solution for bode (lticell{:}), not a workaround ;-)
In control-2.3.54 I've just released, I used the following two hacks in the bode and nyquist functions:

BODE:
-----
      try
        legend_args = cat (2, legend_args, inputname(sys_idx(k)));  # watch out for bode (lticell{:})
      end_try_catch


NYQUIST:
--------
      try
        legend_args{k} = inputname(sys_idx(k));
      catch
        legend_args{k} = "";
      end_try_catch

Thanks again for your responsive help and best regards,
Lukas
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://ad.doubleclick.net/clk;258768047;13503038;j?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev
Reply | Threaded
Open this post in threaded view
|

Re: inputname and function(cell{:})

Jordi Gutiérrez Hermoso-2
On 16 September 2012 00:57, Lukas Reichlin
<[hidden email]> wrote:
> On 15.09.2012, at 16:52, Jordi Gutiérrez Hermoso <[hidden email]> wrote:
>
>> Lukas,
>>
>> This is just off the top of my head and I didn't look at your code in
>> detail, but how about using a struct instead of a cell to pass the
>> arguments and getting the names of the variables with the fieldnames
>> function?

> Hmm, I was looking for a solution for bode (lticell{:}), not a workaround ;-)

There is no solution for that. You have to change the problem if you
want a solution. :-/

- Jordi G. H.

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://ad.doubleclick.net/clk;258768047;13503038;j?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev