You could limit the values in your matrix to the first 4 decimal places but this is usually not a good idea unles there's a reasonable justification to do so. Take a look at the values you mentioned.
format long
Trace_Wc([1,2,7],3)
ans =
1.249999999999995
1.250000000000014
1.249999999999999
As you can see, limiting those values to the first 4 dp will not give you matching values.
Those same values in "short" format are
format short
Trace_Wc([1,2,7],3)
ans =
1.2500
1.2500
1.2500
But the key point is that the format just affects what you see, not the actual values.
If you have principled reason to truncate the precision to 4 decimal places (ie, the instrument used to get the data is only precise to 3 dp), you could do so like this:
Trace_WcNew = round(Trace_Wc, 4);
Instead, if you're trying to find values in a row that are approximately equal to the max value of that row, use a threshold like this:
idx = abs(Trace_Wc(11,:) - max(Trace_Wc(11,:))) < 0.0001
This locates all values in row 11 that are within 0.0001 of the max. Here's what it's returns:
format long
Trace_Wc(11,idx)
ans =
Columns 1 through 6
2.249999999999984 2.249999999999988 2.249999999999990 2.249999999999983 2.249999999999988 2.249999999999987
Columns 7 through 8
2.249999999999988 2.249999999999988
In that case, 0.0001 is somewhat arbitrarily chosen after looking at the data. Instead, you could use a threshold that is 1/10 of 1% of the range of your data such as
threshold = range(Trace_Wc(11,:))*.001
0 Comments
Sign in to comment.