Question about Indexing a function
显示 更早的评论
A = [-1 -2 0 1 2];
B = A(A<0);
What does A(A<0) mean exactly? and is there a way to do its function with an if statement? because I tried this and it did not work.
if A<0
B = A;
end
1 个评论
"What does A(A<0) mean exactly?"
A(A<0)
^^^ logical index
^^ ^ indexing into A
Basic MATLAB concepts, like how to use indexing, are explained here:
"and is there a way to do its function with an if statement?"
It could be done with a bit of effort, but that would be a very poor use of MATLAB.
采纳的回答
更多回答(1 个)
Steven Lord
2021-4-27
2 个投票
That operation is logical indexing. Also see the "Indexing with Logical Values" section on this documentation page for more information.
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!