how to check every single element in a matrix vector wise
40 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
David K.
on 17 Jul 2019
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
More Answers (0)
See Also
Categories
Find more on Matrix Indexing 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!