×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Mathcad WHILE loop inside an IF statement

## Mathcad WHILE loop inside an IF statement

(OP)
Having an problem with a Mathcad WHILE loop (using Mathcad 15). I'm reading data in from a file, the data is from an accelerometer. I want to set up an IF statement to set a variable to 1 when the rising edge of the signal is greater than 5 g's but I don't want to reset the variable back to 0 until the signal drops to below 2 g's. If I do just the IF statement it work fine but switches the variable to 1 on the rising edge of the pulse at 5 g's and sets it back to 0 on the falling edge at 5 g's. I want the variable to be reset back to 0 at 2 g's on the falling edge. Attached is my attempt of a WHILE loop inside a IF statement, I'm having issues trying to determine how to structure the WHILE loop. Any help with this would be appreciated. Attached is a PDF of the waveform and my attempt at the Mathcad programming.

### RE: Mathcad WHILE loop inside an IF statement

what do you want it to do in between 2 and 5? If you want it to be the value from the data you could write it like if(F[i>5,1,if(F[i<2,0,F[i)), so just an if statement within another if statement. depends how you want to treat the internal values.

### RE: Mathcad WHILE loop inside an IF statement

(OP)
StructSU10, When the value is between 5 and 2 I want to output a 1 to a graph and when it's not between 5 and 2 I want to output a 0 to a graph. The issue is on the pulse I am triggering this off of I don't want to trigger the output to a 1 until the rising edge reaches 5 and don't want to trigger the output to a 0 until the falling edge reaches 2 (see attached JPG). Would the equation you had listed do this.

### RE: Mathcad WHILE loop inside an IF statement

(OP)
StructSU10,

I'm looking for a 1's and 0's graph (see attached). I can get this with the single if statement shown above the graphs but it is switching to a 1 at 5 (rising edge of pulse) and a 0 at 5 (falling edge of pulse). What I'm trying to do is switch to a 1 at 5 (rising edge of pulse) and switch to a 0 at 2 (falling edge of pulse). Graph would be 1's and 0's as shown. As I move the value down on the falling edge of the signal this will increase the width of the digital pulses i.e. the amount of time that it stays at a 1.

### RE: Mathcad WHILE loop inside an IF statement

(OP)
IRstuff,

Understand state machines and doing this in standard software programming is straight forward, I'm trying to understand how this needs to be structured in Mathcad 15 so Mathcad understands the equation and can process it. If you have any suggestions on how to do this in Mathcad 15 I would be interested.

### RE: Mathcad WHILE loop inside an IF statement

(OP)
Occupant,

Thank you very much this is exactly what I was trying to do. Plotted out the 1 and 0 states against the waveform and you can see that it is triggering on 5 on the rising edge and 2 on the falling edge (see attached plot). Thanks again.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

#### Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a partâ€™s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!