Extract Values from Matrix row
2 次查看(过去 30 天)
显示 更早的评论
Hi
I have a Dataset padded with -500 so the row length of the matrix stays the same. Now I want to extract an array from a row containing only the values that aren't -500.
e.g
A = [2,1,2,3,4,-500,-500,-500 ; 2,3,4,5,-500,-500,-500,-500]
i've tried this but it gives me only the boolean answer
A1 = A(1,:) > -500 -> A1 = [1,1,1,1,1,0,0,0]
what i want would be A1 = [2,1,2,3,4]
Can anybody help me?
Thanks in Advance
0 个评论
采纳的回答
David Fletcher
2021-4-12
You can use the logical vector to index the main array i.e
A(A1)
1 个评论
Adam Danz
2021-4-12
Better yet, combine them into 1 line,
A1 = A(1,A(1,:)~=-500)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!