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 the Community Ranking System, a fun gamification element of the PTC Community. X

searchig a vector

Tomek1
5-Regular Member

searchig a vector

Hello,

I'm trying to write a program that will look into a vector (for example vector below)

and as an output will return only once each value inside the vector and assign it corresponding number i.e  t1=1, t2=2, t5=5, t7=7, t8=8, t18=18, t88=88

 

Thanks for help

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby V
(To:Tomek1)

You are welcome.

 

i just noticed that the values in my second screen shot are wrong. The reason, fortunately, is not a faulty routine but the fact, that t2 is not only the name of the vector but also a scalar variable which you set for demonstration.

So if you pull down the highlighted regions a bit all is OK:

B.png

View solution in original post

8 REPLIES 8
-MFra-
21-Topaz II
(To:Tomek1)

Hi,

image.jpg

Tomek1
5-Regular Member
(To:Tomek1)

 
Werner_E
24-Ruby V
(To:Tomek1)

This forum is not as comfortable as others.

You can't embed a picture by pasting from the clipboard. Even though it may look good while you edit your post, the picture is gone when you post your message as you can see.

You have to use the camera symbol at the top of the edit window to embed a picture or you may use the button at the lower left to attach a picture.

 

From your description its not clear what you are looking for. I looks like you want to remove duplicate values from a vector, but its not clear what you would like as an output. You have to clarify that by creating the output manually so we see what you are after. Its not clear to me what you mean by "assign it corresponding number" or by "t88=88".

 

And as always: Its always better to attach a worksheet so we have something to play with and also we know that way which version of the software, Prime or real Mathcad, you are using. If you are using Prime and are not using the latest current version, you should say so, as silly Prime can't save  to older Formats of Prime and older Prime versions of course can't read the newer file format.

Just see that you attach a worksheet.

Still not clear what the output of the function you are looking for should be.

You cant create variable names on worksheet level, so all a program could do is return a 3-element vector with the values 111, 222 and 337.

A program can't create a worksheet variable,  name it t111 and assign it a value - thats not possible.

 

What would be possible is, that the program creates a 338x1 matrix with all values being zero except the values at nr 111, 222 and 337 which would have the values corresponding to their number.

 

Anyway, here are some links to threads where you find programs which remove duplicate values from a vector:

https://community.ptc.com/t5/PTC-Mathcad-Questions/How-to-remove-duplicate-entries-in-an-array-using-a-program/m-p/542304/highlight/true#M179429

https://community.ptc.com/t5/PTC-Mathcad-Questions/How-to-remove-duplicates-in-a-matrix-column/m-p/293717/highlight/true#M114533

 

Tomek1
5-Regular Member
(To:Werner_E)

Ok, noted. Will explain properly. Got  a bit frustrated after spending whole day trying to write such program myself. 

I need program to "search" the vector and assign value that equala to that number but only once. There are only 7 possible values that either repeat or  are not included in the vector. For example for t1 it can either assign 279 if this number occurs in the vector or 0 if it doesn't. And it checks the whole vector (which might have 200 entries) for all 7 possible numbers.  Please refer to the attached matcad file which gives an example vector and outputs.

 

Thanks again for your help. 

Werner_E
24-Ruby V
(To:Tomek1)

So as the possible numbers in the vectors is known, thats an easy task. You simply look up the vector for each of this numbers if its there or not.

The following routine should do the job.

B1.png

 

And according the variable names you asked for at first. As the numbers are know, you can do as follows:

B2.png

Tomek1
5-Regular Member
(To:Werner_E)

Thanks!

Werner_E
24-Ruby V
(To:Tomek1)

You are welcome.

 

i just noticed that the values in my second screen shot are wrong. The reason, fortunately, is not a faulty routine but the fact, that t2 is not only the name of the vector but also a scalar variable which you set for demonstration.

So if you pull down the highlighted regions a bit all is OK:

B.png

Top Tags