Compare each elements in a column to a set number, and output results
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all,
I am doing a migration project and having a 289x50 matrix. Each column is the time-lapse displacement. I am trying to set up a value to sort out the elements that moves enough. For example, if a value in a certain place of that column is over 100, mark this column number, stop afterwards search within the same column, and move to the next column. This process continues until the last column is been exexcuted.
I think I can creat a same size matrix to do a matrix compare, but it seems very redundant. I wonder there will be a better and efficient way to make this happen, but having a hard time to find correct info. I really appreciate if someone can provide some hints and directions.
0 commentaires
Réponse acceptée
Image Analyst
le 10 Avr 2022
Try this:
M = randi(200, 289, 50)
[rows, columns] = find(M > 100)
Each corresponding pair of rows and columns will be a row and column where the matrix M is more than 100.
5 commentaires
Image Analyst
le 10 Avr 2022
The reason there are nan's there is that there is no element in the column that is more than 100. If you remove them, then you will no longer have a 50 element wide vector. It will be less, like say 40 long, and those 40 would not correspond to the original 50 column matrix, which could be very confusing. I suggest you leave it and learn how to handle that case, so that the value of firstRow corresponds with the column of the original matrix. If you really want to delete them, you can use isnan
firstRow(isnan(firstRow)) = []; % Dangerous/risky.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!