Filter value from multiple columns
显示 更早的评论
I have the following array named "tNino1_2"
I want to filter the value equal to 1 from columns 20, 21, 22, 23 and 24
The script I'm using is below:
xcol=20:1:24
idx=tNino1_2(tNino1_2(:,xcol)==1,:)
The logical indices in position 1 contain a true value outside of the array bounds.
4 个评论
Voss
2023-2-9
What do you mean by "filter"? What exactly do you want to do when you find a 1 somewhere in columns 20-24? Replace the 1 with NaN or some other value? Remove the entire row from the matrix? Extract those rows into another variable? Etc.
Augusto Gabriel da Costa Pereira
2023-2-9
Dyuman Joshi
2023-2-9
Do you want to find the position (both row and column values) of elements equal to one between columns 20 to 24?
Augusto Gabriel da Costa Pereira
2023-2-9
采纳的回答
更多回答(1 个)
load tNino1_2
"find the values equal to 1 in columns 20 to 24"
[r,c] = find(tNino1_2(:,20:24) == 1)
r is rows and c is columns. Of course, c is relative to columns 20-24 only, so c = 1 means column 20 of the original matrix, c = 2 means column 21, etc.
You can add 19 to c to get the locations of the 1s in the original matrix
c = c+19
Confirm that the elements at those locations are all 1s:
temp = tNino1_2(sub2ind(size(tNino1_2),r,c))
all(temp == 1)
类别
在 帮助中心 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!