how to check every single element in a matrix vector wise
21 次查看(过去 30 天)
显示 更早的评论
i have a matrix of m x n and i want to apply conditions on each single column
- check if any of the value in column is greater then threshold( T1)
- then check all the previous values if any value other than the current value is also higher than (T1)
- then count the number of values including current value
- if count is less than threshold (T2) then replace the current value by 10
looking forward for any help
Thanks
0 个评论
采纳的回答
David K.
2019-7-17
A matrix is indexed like this: A(row,column). So to traverse a single column you leave the second value the same while changing the first value. If you want to find all the values in a column larger than a threshold you can do
A(:,col)>T1;
You can easily count them by using sum
sum(A(:,col)>T1);
You can also replace those values easily like this
A(A(:,col)>T1,col) = 10;
In that we are saying to set the values of A in the desired column that are larger than T1 are to be set to ten.
I am not what it is you are saying but here is a way to do what I think you are describing and if it is not quite right, hopefully I have given you what you need to figure out how to do it.
for n = 1:size(A,col)
if A(n,col) > T1 & sum(A(1:n-1,col)>T1)<T2
A(n,col) = 10;
end
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!