在MATLAB中消除连续区域(一般化:介于零之间的区域)

时间:2018-10-01 18:30:20

标签: matlab vectorization

我需要有效地消除(通过归零)矩阵A每一列处“ -1”之间的连续“ 1”,该矩阵现在可以被任何零分隔。在“ -1”之间的连续“ 1”数大于N。这是我先前的Question的简单概括。

再次,典型尺寸(A)= [100000,1000]。

查看示例:

 public function ajaxResponse(Request $request){
        if ($request->ajax()) {
            $mat_id = $request->input('mat');
            $cat_id = $request->input('cat');
            $met_id = $request->input('met');

            $products = Product::query();
            if ($cat_id != null) {
                $products->whereHas("categories", function ($query) use ($cat_id) {
                    $query->whereIn('category_id', explode(',', $cat_id));
                })->get();
            }
            if ($mat_id != null) {
                 $products->whereHas("productMaterial", function ($query) use ($mat_id) {
                    $query->whereIn('product_material_id', explode(',', $mat_id));
                })->get();
            }
            if ($met_id != null) {
                $products->whereHas("productionMethod", function ($query) use ($met_id) {
                    $query->whereIn('production_method_id', explode(',', $met_id));
                })->get();
            }

            $products = $products->get();

            $prod = view('partials.ajaxProducts', ['products' => $products])->render();
        }
        return response()->json(['prod' => $prod]);
    }

对于N = 2,预期结果是

  A =
       1    -1     0
       0     1     1
       0     1     1
       1     1     0
       0     0     1
       1    -1     0
      -1     1     1
      -1     0    -1
       1     1     1
       0     1    -1

对于N = 3,预期结果是

Aclean =
       0    -1     0
       0     0     0
       0     0     0
       0     0     0
       0     0     0
       0    -1     0
      -1     0     0
      -1     0    -1
       1     0     1
       0     0    -1

1 个答案:

答案 0 :(得分:2)

如果我理解这个问题,可以使用with open("stopwords.txt", "r") as f: new_stopwords = [] for line in f.readlines() new_stopwords.append(line) new_stopwords_set = set(new_stopwords) cumsum

accumarray