help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: re-assign special values in matrix


From: Isak Delberth Davids
Subject: Re: re-assign special values in matrix
Date: Fri, 12 Nov 2010 09:19:22 +0200



On 12 November 2010 08:35, David Bateman <address@hidden> wrote:
James Sherman Jr. wrote:
> On Fri, Nov 12, 2010 at 1:04 AM, Isak Delberth Davids <address@hidden
>
>> wrote:
>>
>
>
>> Here comes a lay-man,
>>
>> I intend to avoid dividing by zero, by re-assigning a different value to a
>> entry that is zero in a divisor matrix. In the following code I want to
>> search for that entry of A which equals zero (being A(7) in this case), and
>> give it a value that is greater then zero but smaller than all other
>> non-zero entries (which is A(3)=9 in this case). I am trying a if-statement
>> as can be seen --- which seems WRONG. Where should I fix?
>>
>> % code begin
>> clear;clc;
>>
>> a = [3; 2; 1; 3; 4; 5; 1]
>> A = [12; 11; 9; 13; 67; 44; 0]
>>
>> min(A(A~=0)) = A(A==0) % trying to set the zero values in divisor matrix to
>> the min non-zero entry?
>>
>> B = a./A
>> % code begin
>>
>>
>>
> Hi,
>
> You have it almost what you want to do.  The thing is, that unlike
> mathematics, whether you put things on the left hand side or right hand side
> of the equals sign matters in octave (and in programming in general).  So,
> for example, let
> A = [1;2]
> B = [3;4]
> then, executing
> A = B
> would put all the values of B into A and after this command, B would be
> unchanged and A would be equal to [3;4].
> On the other hand, if you did
> A = [1;2]
> B = [3;4]
> then did
> B = A
> You would have A unchanged and B would be equal to [1;2].
>
> So, for your example, you would want:
> A(A==0) = min(A(A~=0));
> should do the trick.
>
> Hope this helps.
>
>

If you are just trying to get rid of the warning then why not just turn
the warning off with

warning ("Octave:divide-by-zero","off")

D.

OK, I now take note that one can switch a warning off, however in my case I need to proceed with other computations and having a "Inf" value halts the program. Thanks D.

IDD

--
* * * * * * * * * * * * * * *
*  Isak Delbert Davids *
*  +264-81-33 049 33  *
*  +264-61-206 3789   *
*    Namibia, Afrika     *
* * * * * * * * * * * * * * *


reply via email to

[Prev in Thread] Current Thread [Next in Thread]