how to select higher value in a matrix and change that by introducing an error?
显示 更早的评论
I have a matrix,
a= [ 0.83 0.85 0.97 0.1 0.95 0.93 0.2 ; 0.2 0.12 0.12 0.76 0.77 0.78 0.25 ; 0.88 0.32 0.11 0.77 0.87 0.89 0.99]
by ceil(a) we get c matrix: c=[ 1 1 1 0 1 1 0 ; 0 0 0 1 1 1 0 ; 1 0 0 1 1 1 1]
now i want to introduce error position wise as err=1:3
so, at first err=1 will be introduced to first row where the only highest value is find in matrix a and 1 will become 0,same wise in 2nd row and 3rd row. Then err=2, that means the first two highest value is find and 1 will become zero, then same will be carried out for 2nd,3rd row. Next err=3...where 3 higher value will be changed.
please help me out asap....
plz plz plz.....
5 个评论
J. van Delft
2014-6-2
First of all, the ceil command rounds the elements of a to the nearest integers greater than or equal to a. So your matrix c will consist of only 1's. Instead you could use "round" to produce the results you want.
Next, the "max" command is able to give you the value and position of the maximum value of your matrix. For example, for the 1st row of a:
[val,pos] = max(a(1,:));
This will give you val = 0.97, pos = 3. Then simply change the value of the element corresponding to pos = 3 in the c-matrix:
c(1,pos) = 0
A for-loop can reproduce the same results for the 2nd and 3rd row.
After this you can repeat the process to find the second highest value. Don't forget to change the highest value you found before to zero or else you'll find the same result over and over again.
suchismita
2014-6-2
the cyclist
2014-6-2
You can use the sort() command rather than the max() command to find multiple values.
suchismita
2014-6-2
Roger Wohlwend
2014-6-2
Yes, but the sort command also tells you the original position of the sorted values (it's the second output variable). Use that information.
采纳的回答
更多回答(1 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!