英文:
Is there any function for matlab to concantenate array using condition?
问题
我有这段Python代码,用多个条件来连接两个数组,如下所示:
good_left_inds = ((nonzeroy >= win_y_low) & (nonzeroy < win_y_high) &
(nonzerox >= win_xleft_low) & (nonzerox < win_xleft_high)).nonzero()
是否有MatLab等效的代码可以处理这种类型的数组?
英文:
I have this python code for concatenating 2 arrays using multiple conditions like give below
good_left_inds = ((nonzeroy >= win_y_low) & (nonzeroy < win_y_high) &
(nonzerox >= win_xleft_low) & (nonzerox < win_xleft_high)).nonzero()
is there any MatLab equivalent code to work on this kind of array?
答案1
得分: 1
是的,有的。请查看MATLAB的find
函数。其文档说
> 查找非零元素的索引和值
这基本上与numpy.nonzero
做的事情相同。逻辑表达式在实际上与Python代码几乎相同。
<!-- language: matlab -->
% 您只对索引感兴趣,因此可以省略返回参数中的值
[good_left_inds,〜] = find(nonzerox>=win_y_low&nonzerox<win_y_high&...
nonzerox>=win_xleft_low&nonzerox<win_xleft_high);
在比较结果时,请记住MATLAB的索引从1
开始,而不是像Python中的0
。
英文:
Yes, there is. Have a look at MATLABs find
function. Its documentation says
> Find indices and values of nonzero elements
It is basically the same what numpy.nonzero
does. The logical expressions are practically identical to python code.
<!-- language: matlab -->
% You are only interested in the indices, so you can omit the values as return parameter
[good_left_inds, ~] = find(nonzerox >= win_y_low & nonzerox < win_y_high & ...
nonzerox >= win_xleft_low & nonzerox < win_xleft_high);
When comparing the results, please remember that MATLAB indexing starts at 1
and not at 0
like in python.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论