how to check every single element in a matrix vector wise
조회 수: 27 (최근 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!