【问题标题】:Matlab: Deleting elements from a vectorMatlab:从向量中删除元素
【发布时间】:2014-03-30 22:07:42
【问题描述】:

我不确定为什么下面的代码不起作用。我基本上试图摆脱probofdetectionanddelamprop 中等于1 或小于10e-12 的元素,这意味着probofdetectionanddelamprop 的大小是动态变化的。因此,我添加了一个 while 循环来检查 i 何时等于新的 size(probofdetectionanddelamprop),但这似乎不起作用。

while i ~= numel(probofdetectionanddelamprop)
for i = 1:no_iterations % Clearly, no_iterations is > numel(probofdetectionanddelamprop)
    if (probofdetectionanddelamprop(i) <=10e-12 || probofdetectionanddelamprop(i) == 1)
        probofdetectionanddelamprop(i) = [];     
    end
end
end

谢谢

【问题讨论】:

    标签: matlab loops


    【解决方案1】:

    这个怎么样:

    probofdetectionanddelamprop(probofdetectionanddelamprop < 1e-11 | probofdetectionanddelamprop == 1) = [];
    

    【讨论】:

    • 谢谢。有没有办法追踪probofdetectionanddelamprop的哪些元素被删除了?
    • 语句probofdetectionanddelamprop &lt; 1e-11probofdetectionanddelamprop == 1都是逻辑数组。它们等于 1 的位置表示选择了该元素。如果你想选择一个整数数组索引,你可以说find(probofdetectionanddelamprop &lt; 1e-11 | probofdetectionanddelamprop == 1)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-05
    • 2020-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多