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

1-Newbie

## For loop error

I'm new to MathCAD(using MathCAD15). I'm trying to write a program that iterates through a set of data to locate the falling edge of a trip signal. The data set I am working with has thousands of lines where the voltage drops from arround 2.5v to around zero at the time a machine trips offline. I wrote a silplified program with only 10 datapoints as a baby step tward my goal. I am getting an error that doesnt make sense to me. "This value must be a Matrix of scalar elements"

See the attached program, any help is appriciated.

1 ACCEPTED SOLUTION

Accepted Solutions
19-Tanzanite
(To:ptc-6192752)

It would be easier if you attach a worksheet. It's hard to debug an image.

Probably, if you right click on the absolute value operator, |, it will be set to "square matrix determinant". Select "absolute value" instead.

8 REPLIES 8
15-Moonstone
(To:ptc-6192752)

1. Instead of n0,0 and ni,0 just use n0 and ni, because n is just a vector.

2. Better to upload a worksheet, not just an image.

Alan

19-Tanzanite
(To:ptc-6192752)

It would be easier if you attach a worksheet. It's hard to debug an image.

Probably, if you right click on the absolute value operator, |, it will be set to "square matrix determinant". Select "absolute value" instead.

1-Newbie
(To:ptc-6192752)

Thanks guys. I had been fighting with that for about an hour. You answered my question in <5min.

24-Ruby IV
(To:ptc-6192752)

Instead of for and break you could use the while-statement:

The result of my routine differes from yours when the vector consists of 1's only. Not sure what result you expect in that case.

4-Participant
(To:ptc-6192752)

Another routine using a For Loop.

24-Ruby IV
(To:MikeArmstrong)

A good one!

And while we are at that "make it shorter" contest, here a a very short and completely different approach:

It throws an error if the vector consist of all 1's which can easily be coped with an "onerror" statement.

BTW, I feel that a for-loop should not be terminated prematurely, whether using break or using return. But I admit that thats a very puristic point of view. And I am very often missing a "do-while" or "Repeat-Until" construction.

4-Participant
(To:Werner_E)
 Werner Exinger wrote:A good one!And while we are at that "make it shorter" contest, here a a very short and completely different approach:

I like it

 Werner Exinger wrote:BTW, I feel that a for-loop should not be terminated prematurely, whether using break or using return.

To be honest I do not usually construct for-loops that way, but the eager to reduce the program lines got to me.

24-Ruby IV
(To:MikeArmstrong)
 To be honest I do not usually construct for-loops that way, but the eager to reduce the program lines got to me.

I understand what you mean ;-). I won't recommend my last one as well as for bad readability.

Announcements
Check out the latest