Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replacement based on index

I have 2 vectors like this:

rawRT (nx1 double)

354
521
0
428
568
0
289
...
552

prob (nx1 double)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.82
.75
.59
.27
.67
.36
...
.12

Each value in rawRT corresponds to the value of the same order/location in prob. First, I want to apply some sort of transform to the values in prob if their corresponding values in rawRT is greater than zero.

I could do this: index = rawRT>0. Next, I find the values in prob that correspond to the ones in rawRT that are greater than 0: prob_temp = prob(index). Next, I apply the transform: prob_transform = [some function](prob_temp).

Now, what I am not sure how to do is to replace the values in prob with values from prob_transform in a way that the values that were NOT transformed in prob will remain intact. So in this example, prob(1,1), prob(2,1) will be replaced by values from prob_transform while prob(3,1) will remain the same as original.

Could anyone help?

>Solution :

You just use the same index again for assignment

prob(index) = prob_transform;

You could do this all in one hit

index = rawRT>0;
prob(index) = someFunction( prob(index) );
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading