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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Create vector from array of data

DickCun
12-Amethyst

Create vector from array of data

Hi......

I am attempting to create a single vector from a two column array. The fist column contains the values  and the second column the occurrences associated with each value. I have attached a worksheet , in MathCAD 15,  that shows what i am attempting to do. I can solve the problem by performing each row of the array separately but hit a snag when trying to program the same. Would appreciate help in solving the program error I have.

Thanks in advance for help

Dick Cunningham

6 REPLIES 6

Hear must be the for cycle too!

LucMeekes
23-Emerald III
(To:ValeryOchkov)

There are several things wrong in your program.

1.

The operation of your 'for' loop is that it assigns to 'j' the values 0  up to N-1 subsequently.

You tear that down by immediately inside the loop assigning 0 to 'j' with 'j<-0'; no matter which run of the 'for' loop you're in, 'j' is always 0 inside. This makes 'k' to be a range from 0,1...Occur 0-1. It is also not necessary to increment ('j<-j+1')  at the end of the loop, because that is also implied in the 'for' loop operation. In your case it assigns j+1=0+1=1 to j. So j becomes 1. Always.

2.

The index into an array for assignment must be an integer, cannot be a range. That's why you get an error flagged at the assignment to 'Val k'.

3.

The stack() function is useless when called with a single argument. Stack() wants to stack (at least) two things; 'stack(Val)' just gives 'Val'.

My guess is that you're after something like this:

Success!

Luc

LucMeekes
23-Emerald III
(To:LucMeekes)

Correction. This, I think, is what you're trying to do:

Success!
Luc

LucMeekes
23-Emerald III
(To:LucMeekes)

Or, a little shorter:

Luc

StuartBruff
23-Emerald III
(To:DickCun)

Heres's another variant ...

Stuart

DickCun
12-Amethyst
(To:DickCun)

Hey Guys.....

Once again I get very quick responses to a problem. Thanks to all of you for providing answer to my question.

Dick..

Announcements

Top Tags