Resources

substitute

0

Hi,

I have the following line in my code with the intention to replace some elements in matrix ini1 with 1. However, the matrix stays the same. I wonder if there is anything wrong with my use of substute.

ini1[.,q]=substute(ini1[.,q], inn[.,q]-0.01.<0, 1);

Thank you!

Tags: asked April 4, 2013

2 Answers

0

Your code should make some changes to ini1 if some of the elements in the qth column are less than 0.01. Here is a little self-contained example:

inn = { 1, 0.001, 0, 2, 3 };
ini1 = 999*ones(rows(inn), 1);
q = 1;

print "before substute, ini1 = " ini1;
ini1[.,q]=substute(ini1[.,q], inn[.,q]-0.01.<0, 1);
print "after substute, ini1 = " ini1;

The output from this code is:

before substute, ini1 = 
       999.00000 
       999.00000 
       999.00000 
       999.00000 
       999.00000 
after substute, ini1 = 
       999.00000 
       1.0000000 
       1.0000000 
       999.00000 
       999.00000 
aptech
342
0

I might try calculating the separate input on another line of code and then take a look at it to see if it has any 1's in it, like this:

mask = (inn[.,q] - 0.01) .< 0;
print mask;
ini1[.,q]=substute(ini1[.,q], mask, 1);

If there are no 1's in the print out of mask then that is the problem.

aptech
342