Compare each elements in a column to a set number, and output results

3 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Image Analyst
Image Analyst el 10 de Abr. de 2022
Try this:
M = randi(200, 289, 50)
M = 289×50
24 154 168 107 159 139 160 192 111 61 14 125 177 107 175 24 68 129 192 99 172 94 200 2 200 172 153 135 103 159 16 58 105 171 133 137 87 9 172 113 130 88 28 22 177 110 68 3 160 114 21 6 169 142 105 189 170 96 190 5 138 200 184 154 73 46 127 63 165 125 87 200 28 17 200 158 168 82 143 179 191 180 73 162 165 110 53 158 70 109 66 144 97 94 138 40 112 111 99 117 7 54 80 19 176 46 81 130 13 91 98 54 23 85 42 102 86 111 191 77 104 76 23 178 99 55 14 55 81 85 164 23 47 78 54 60 81 171 81 8 17 36 103 166 117 104 152 62 90 17 170 105 21 100 165 80 191 176 19 66 183 49 159 93 163 163 195 144 7 83 90 144 73 33 72 19 183 19 22 183 122 3 4 110 155 169 91 19 157 119 41 164 26 95 138 15 134 37 163 175 88 52 2 90 101 116 8 38 83 174 123 66 43 61 32 172 109 31 180 39 151 170 145 174 86 86 12 146 102 103 181 108 131 81 91 128 190 147 35 38 165 169 39 126 126 99 105 104 182 121 38 30 58 172 106 69 23 76 152 70 34 95 168 60 193 61 87 29 3 161 54 116 150 19 42 151 101 165 183 47 119 72 57 183 39 8 79 30 15 23 181 91 49 190 7 97 199 146 24 13
[rows, columns] = find(M > 100)
rows = 7232×1
3 5 6 7 8 9 16 17 18 21
columns = 7232×1
1 1 1 1 1 1 1 1 1 1
Each corresponding pair of rows and columns will be a row and column where the matrix M is more than 100.
  5 comentarios
Image Analyst
Image Analyst el 10 de Abr. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by