Matlab的嵌套`if'的简写(如Python的列表理解) [英] Matlab shorthand for `for` with nested `if` (like Python's list comprehension)
问题描述
这个问题不知何故解决了这个问题,但不是从我想找的一方。
我想将一个数组映射到另一个数组中,阈。对于循环来说,基本上是一个 我知道 有没有一种方法可以通过内联指令来执行这个任务? < This question somehow addresses the problem, but not from the side I'm looking for. I'd like to map an array into another, picking only the elements below a certain threshold. Basically a I'm aware of the Is there a way to perform this task with an inline instruction? Maybe this is what you are looking for:
这篇关于Matlab的嵌套`if'的简写(如Python的列表理解)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!,用
if
条件语句来检查阈值。
arrayfun
函数,但我不知道如何在没有定义新函数的情况下将条件语句放入其中。 / p>
A =(0:49)./ 50; %生成初始数组。
B = A(A <0.5); %将一个数组映射到另一个数组中,仅挑选低于某个阈值的元素。
for
loop, with an if
conditional statement which checks the threshold.arrayfun
function, but I don't know a way to put the conditional statement in it without defining a new function. A = (0:49) ./ 50; % Generate the initial array.
B = A( A < 0.5 ); % Map an array into another, picking only the elements below a certain threshold.