Matching the maximum Values in a matrix from another vector
2 views (last 30 days)
Show older comments
Yaser Khojah
on 15 Oct 2018
Commented: Yaser Khojah
on 16 Oct 2018
I have a matrix with size of 21600 x 2 as Matrix_Vector = [STD_v,NPV_v]; I'm trying to find the values that matching xvalues = [0:.1:35] from STD_V.
So, I used this code:
[ d, ix ] = min( abs( STD_v-xvalues ) );
Matrix_Vector_updated = [STD_v(ix),NPV_v(ix)];
However, I still see values in Matrix_Vector_updated share the same values as 0.468 as below:
0.468490416082415 -68.0623566640544
0.468490416082415 -68.0623566640544
0.468490416082415 -68.0623566640544
0.468490416082415 -68.0623566640544
0.468490416082415 -68.0623566640544
0.468490416082415 -68.0623566640544
0.468490416082415 -68.0623566640544
0.861091227948802 -62.0460361812610
0.861091227948802 -62.0460361812610
0.920662009016715 -52.2025156248263
0.920662009016715 -52.2025156248263
1.08087425638995 -34.5197924821680
1.21018219911556 -45.0147047153047
1.31409003462488 -62.4048732765717
1.40064375002948 -49.6318599064140
1.50221080043184 -60.8266330903523
1.61795597497108 -48.3442487471706
1.68219041491832 -37.6318990471176
I'm trying to limit my numbers to the following format where I get only one value from NPV_v (the maximum if there is more than a value) corresponding to each value in STD_V:
0
0.100000000000000
0.200000000000000
0.300000000000000
0.400000000000000
0.500000000000000
0.600000000000000
0.700000000000000
0.800000000000000
0.900000000000000
1
Can anyone help please
4 Comments
Bruno Luong
on 15 Oct 2018
"just want to select the maximum value"
I'm just unsure what you meant by that. You list a bunch of numbers without commenting where they come from.
And those number inside the odd IF
if true
....
end
This kind of language is not what I can read and interpret.
Accepted Answer
Andrei Bobrov
on 15 Oct 2018
lo = ismembertol(STD_v,xvalues,.01,'DataScale',1);
Matrix_Vector_updated = [STD_v(lo),NPV_v(lo)];
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!