Skip to main content
1-Visitor
September 15, 2015
Solved

return an array from another array

  • September 15, 2015
  • 2 replies
  • 3861 views

Hello everyone,

I have a question from extracting an array.

Suppose I have an array A=[0 0 0 0 1 1 1 1 1 1 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 2 2 2 2 2]

How can I extract a subarray B=[0 1 3 4 2]

I am new to mathcad. Thank you for your help in advance.

Son

Best answer by StuartBruff

NGUYEN Van Son wrote:

Hello everyone,

I have a question from extracting an array.

Suppose I have an array A=[0 0 0 0 1 1 1 1 1 1 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 2 2 2 2 2]

How can I extract a subarray B=[0 1 3 4 2]

I am new to mathcad. Thank you for your help in advance.

With a bit of programming.

Stuart

2 replies

23-Emerald V
September 16, 2015

NGUYEN Van Son wrote:

Hello everyone,

I have a question from extracting an array.

Suppose I have an array A=[0 0 0 0 1 1 1 1 1 1 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 2 2 2 2 2]

How can I extract a subarray B=[0 1 3 4 2]

I am new to mathcad. Thank you for your help in advance.

With a bit of programming.

Stuart

1-Visitor
September 17, 2015

Slight alternative to Stuarts method using a while loop.

Mike

nvanson1-VisitorAuthor
1-Visitor
September 17, 2015

hello Mike,

Thank you very much for your response.

Are the elements of array: Duplicate3(M)=(0 1 2 3) taken from the last value (I underlined below) of each similar sequence? or arbitrary?

M:= (0 0 0 0 1 1 1 1 2 2 2 3 3 3 3 3 3)

If no, how can we know that?

And is the commande V<-- sort(M) is used to sort M?

If yes, I dont need this because I want an array randomly , like N:=(0 0 0 8 8 8 8 10 10 10 5 5 5 5 5 5 1 1 1 1 1 1 1 )

Thank you very much,

NGUYEN

1-Visitor
September 17, 2015

A slight alternative which will return the duplicated values and non-duplicated values. No what was requested but could be of some use.

Mike