cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

On Error Programming

ptc-5152170
7-Bedrock

On Error Programming

Hey

I'm kinda new to Mathcad, but it works ;D
Now I'm wondering if there is any possibility to use "on error" programming. (see attachement)

I want to return "1" if the match function found at least one zero element in a collumn of the given and "0" if not.
"0" won't work because of the error message by Matchcad.


The example is in German, so here the commands in English:

vergleich(z,A) = match(z,A)

And my own procedure: istNullVorhanden="isAnyZeroElement"

I use Mathcad 15. I also try to find a clue in previous community entries, but I only found the statement that "on error" programming is a way for the match() function.

Thank you for every help ♥

ACCEPTED SOLUTION

Accepted Solutions

But it worked for me. I got my "1" and "0" by adding just a little change.
match_example.png

Maybe this isn't the finest way for this, but at the moment it helped out.

View solution in original post

8 REPLIES 8

Like so:

match.PNG

Alan

Werner_E
25-Diamond I
(To:AlanStevens)

The problem with this method is, that it will return 0 if no match is found but will also return 0 if a match (a zero) is in the first position (index 0).

But it worked for me. I got my "1" and "0" by adding just a little change.
match_example.png

Maybe this isn't the finest way for this, but at the moment it helped out.

Werner_E
25-Diamond I
(To:ptc-5152170)

Yes, your modification cured it and its as good and fine as any other.

You may shorten it a bit by getting rid of the t-assignment, the if statement and the vector index 0 if you like. The point is that, because of the return in the first line, the second line is is evaluated only if a zero was found.

match2.png

Werner_E
25-Diamond I
(To:ptc-5152170)

In the future please attach the Mathcad worksheet, not just a pic.

You are right, you will need the "on error" construct as match will throw an error in case it does not find a match.

One possible way

Nullen.png

Another way would be to do without match and simply compare the product of the vector elements against zero - see attached.

A more natural way would be to write ones own count() routine.

Thank you so much you two! ^.^

AlanStevens' answer help atm but thank you Werner for your annotations! I think I can use them later.

Well, but after I read "on error" and searched for it in Mathcad (programming window) I was little ashamed... I didn't noticed that there was "on error" function already displayed before... Sorry guys!

Actually I'm not a fan of "programming by clicking" everything together, but there is no other opportunity,isn't it? 😕

Werner_E
25-Diamond I
(To:ptc-5152170)

Actually I'm not a fan of "programming by clicking" everything together, but there is no other opportunity,isn't it? 😕

You cannot just type in those tokens, only alternative to clicking is the use of the keyboard shortcuts. But be aware that in the localized version they do not all work as stated in the help or tooltip. E.g. "on error" is not Ctrl+' but Ctrl+ä in the German version, or better said with a German keyboord layout.

E.g. "on error" is not Ctrl+' but Ctrl+ä in the German version, or better said with a German keyboord layout.

Yup, I noticed that.

So I rather will just click. But you accustom yourself to it in time I think.

Announcements

Top Tags