From help-octave-request at che dot utexas dot edu Mon Jan 16 19:56:44 1995 Subject: Indexing "1-vectors" From: Ted dot Harding at nessie dot mcc dot ac dot uk (Ted Harding) To: help-octave at che dot utexas dot edu Date: Tue, 17 Jan 1995 01:55:21 +0100 (GMT) Apologies if this has all been settled before. Using Octave-1.0, I have written a function which works fine with vector arguments. It includes lines like rhod( rhod<=-1 ) = 0.5*( rho0( rhod<=-1 ) - 1); to modify those elements of a vector satisfying a condition, namely " rhod(i) <= -1 ", with reference to another vector rho0. So far so good, provided the variables are vectors with more than one element. But I would also like this function to work if the arguments (and therefore the variables like "rhod", "rho0") are 1x1 matrices (equivalent to scalars). However, in such a case when the condtion is false, Octave says error: index invalid or out of range for scalar type and there seems to be no way to prevent this. Yet, if Octave could be forced to view the "scalar" as a vector of length 1 rather than as a scalar proper, the indexing behaviour should also work in this case, according to the rule which seems to apply for M-vectors, namely:- For M-vectors A, B, C A( boolean_fn(C) ) = B( boolean_fn(C) ) should carry out the assignment A(i)=B(i) for elements (i) for which boolean_fn(C(i)) is true, and do nothing for all other (i). This works even if there are no elements (i) for which the condition is true. The dimension does not have to be greater than one for this rule to be workable. Is it possible to force this behaviour in Octave-1.0, or do I have to write a special-case "if ... " section to cope with the scalar case? With thanks, Ted. (Ted dot Harding at nessie dot mcc dot ac dot uk)