25 Replies Latest reply: Mar 20, 2012 11:33 AM by MikeArmstrong

# Replace negative numbers in a Column Matrix with a different number.

Hello,

I have a column of data.

If the column of data has a negative number, I would like to replace that number with a very small positive number, 10^-5.

I've attached my worksheet explaining what I want to do.

Thanks!

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

May be so:

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

How about the attached, slightly different approach to Valery's.

Mike

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

Here's a third method. ( wonder how many different ways we could come up with!)

Alan

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

Here's a third method. ( wonder how many different ways we could come up with!)

Very nice.

I always look forward to seeing your examples.

Mike

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

AlanStevens wrote:

Here's a third method. ( wonder how many different ways we could come up with!)

Alan

The best method is not a ***.xmcd.zip but the PICTURE

I have no time for Mathcad open, the file open (zip -> xmcd) etc for this simple task...

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

The best method is not a ***.xmcd.zip but the PICTURE

I have no time for Mathcad open, the file open (zip -> xmcd) etc for this simple task...

On that note......

Mike

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

Valery Ochkov wrote:

The best method is not a ***.xmcd.zip but the PICTURE

I have no time for Mathcad open, the file open (zip -> xmcd) etc for this simple task...

You're right, but it's taken me half-an-hour to figure out how to do it! I've copied to Paint and saved as a .png file, but is there a more direct way from within Mathcad itself?

Alan

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

AlanStevens wrote:

Valery Ochkov wrote:

The best method is not a ***.xmcd.zip but the PICTURE

I have no time for Mathcad open, the file open (zip -> xmcd) etc for this simple task...

You're right, but it's taken me half-an-hour to figure out how to do it! I've copied to Paint and saved as a .png file, but is there a more direct way from within Mathcad itself?

Alan

half-an-minute for me

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

Valery Ochkov wrote:

half-an-minute for me

Hopefully, for me also in future!

Alan

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

and another variation in just 2 lines

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

Alan,

I copy and paste straight into IrfanView (Which is freeware) and save the image that make literally less than a minute.

Mike

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

david h wrote:

Hello,

I have a column of data.

If the column of data has a negative number, I would like to replace that number with a very small positive number, 10^-5.

I've attached my worksheet explaining what I want to do.

Thanks!

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

Wow!

Thanks for all of the advice. I supposed I started a competition.

Let me take a look...

It looks like Ian's was the most straight forward, though they were all good!

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

I have to disagree. He has used a range variable which I try and keep away from at all costs.

All work, so all good :-)

Mike

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

I am a novice user, so I don't know the benefits of not using range variables. Why do you stay away from them? I suppose I should know.

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

I don't agree with Mike on this one, range variables are fine. Problems can arise when using range variables as variables, like x=2...10 and then using x in equations. Using range variables to construct x is fine.

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

They are useful in some applications, but the majority of Mathcad functions work with vectors. Why define the variable at worksheet level when it can be defined within the program?

I've always tried to stay away from range variables - just a personell opinion though.

Mike

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

I did this a long time ago, it's a portion of an shear wall interaction diagram calc, and I would probably change some things if I were to rewrite it now, but there is nothing wrong and the use of the range variable is clear, even to someone that does not know mathcad. (Vectorizing would not be obvious to a nonuser)

Personally, I find it easier to write this way first, and if necessary, go back after it's verified to change to programs and possibly use vectorization. Debugging is a bugger.

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

I do agree that in certain applications the use of range variables is valid, but as you said it comes down to personnel preference.

Mike

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

I agree, personal preference, and experience.

But, the range variable is getting a bat rap, it is a very powerful variable and I (and I assume many) have, and will, used it extensively. You should not try to stay away from it, just don't use it as a variable, use it as intended, an index

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

As I have said below, because the majority of Mathcad functions work with vectors, which hasn't been created using Ian's method.

Mike

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

david h wrote:

Wow!

Let me take a look...

Russian Prince Alexei takes a look (chooses) on his bride :

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

I think me and you were left on the stand :-).

Mike

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

Mike Armstrong wrote:

I think me and you were left on the stand :-).

Mike

She was Maria Miloslavskaya- see http://en.wikipedia.org/wiki/Maria_Miloslavskaya

• ###### Re: Replace negative numbers in a Column Matrix with a different number.

Brillant.

Mike