Skip to main content
1-Visitor
May 20, 2016
Question

Create vector from array of data

  • May 20, 2016
  • 3 replies
  • 2797 views

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

3 replies

24-Ruby IV
May 20, 2016

Hear must be the for cycle too!

23-Emerald IV
May 20, 2016

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

23-Emerald IV
May 20, 2016

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

Success!
Luc

23-Emerald V
May 20, 2016
DickCun1-VisitorAuthor
1-Visitor
May 20, 2016

Hey Guys.....

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

Dick..