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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

For loop error

ptc-6192752
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
RichardJ
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.

View solution in original post

8 REPLIES 8

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

RichardJ
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.

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

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

17.06.png

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.

MikeArmstrong
5-Regular Member
(To:ptc-6192752)

Another routine using a For Loop.

Clipboard01.jpg

A good one!

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

18.06.png

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.

MikeArmstrong
5-Regular Member
(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:

18.06.png

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.

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.

Top Tags