I and J variables

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

I and J variables

Eyal Doron
Hi,
   I know its a feature, but IMHO its an irritating one. I and J are
defined as sqrt(-1), like i and j, except that they are read-only
and can't be changed. This is playing havoc with some of my MATLAB
functions, which usually use I as an index vector and J as a bessel
function vector. I know its trivial to fix my files, but its
bothersome nevertheless. Is there any way to remove this feature?

BTW, I've just transferred a bessel function .m file from Matlab to
Octave 1.1.0. I needed to change the I variable name, and I also
got the warning: "warning: empty matrix found in matrix list" on
the lines
     Ii=find(z); LI=length(Ii);
     Jn(:,Ii)=[ones(1,LI);zeros(n,LI)];
when "z" contained only zeros. It seemed to work OK, though. I think
these warnings are superfluous, since empty matrices are not an error
but a natural part of the language. Again, solved by enclosing the
whole thing in an "if any(z)==1,...,end" block, which is however not
necessary in Matlab. Nevertheless, I'm impressed.

Bye,
   Eyal Doron

Reply | Threaded
Open this post in threaded view
|

Re: I and J variables

John Eaton-4
Eyal Doron <[hidden email]> wrote:

: BTW, I've just transferred a bessel function .m file from Matlab to
: Octave 1.1.0. I needed to change the I variable name, and I also
: got the warning: "warning: empty matrix found in matrix list" on
: the lines
:      Ii=find(z); LI=length(Ii);
:      Jn(:,Ii)=[ones(1,LI);zeros(n,LI)];
: when "z" contained only zeros. It seemed to work OK, though. I think
: these warnings are superfluous, since empty matrices are not an error
: but a natural part of the language. Again, solved by enclosing the
: whole thing in an "if any(z)==1,...,end" block, which is however not
: necessary in Matlab. Nevertheless, I'm impressed.

You can turn this warning off by setting the built-in variable

  empty_list_elements_ok = "true"

The default value is "warn".  You can also make it invalid to have an
empty matrix in a matrix list by setting the variable to "false".

jwe

Reply | Threaded
Open this post in threaded view
|

Re: I and J variables

John Eaton-4
In reply to this post by Eyal Doron
Eyal Doron <[hidden email]> wrote:

:    I know its a feature, but IMHO its an irritating one. I and J are
: defined as sqrt(-1), like i and j, except that they are read-only
: and can't be changed. This is playing havoc with some of my MATLAB
: functions, which usually use I as an index vector and J as a bessel
: function vector. I know its trivial to fix my files, but its
: bothersome nevertheless. Is there any way to remove this feature?

There is currently no way to avoid this problem.

I will add this to the list of things to look at for 1.2.  To make it
work right (including things like ensuring reasonable behavior if
someone makes `I' global and then changes its value) requires too many
changes to consider it for a 1.1.x release.

Thanks,

jwe