フィルターのクリア

Sum if conditions are satisfied across arrays

2 ビュー (過去 30 日間)
Abhishek Varghese
Abhishek Varghese 2018 年 2 月 14 日
編集済み: Abhishek Varghese 2018 年 2 月 14 日
Hello everyone,
Kinda stuck. Scenario is:
I have a binary 2D array that is n rows and m columns.
I want to count how many times an element went from being a '1' in one row, to a '0' in the next row, and store it as a vector.
I have updated an illustration to help.
Would really appreciate an efficient and simple solution, cheers.
  2 件のコメント
Matt J
Matt J 2018 年 2 月 14 日
I have a binary 2D array that is m rows and n columns.
According to your diagram, n is the number of rows, not columns.
Abhishek Varghese
Abhishek Varghese 2018 年 2 月 14 日
That's right. Edited it now. Thanks

サインインしてコメントする。

採用された回答

Matt J
Matt J 2018 年 2 月 14 日
編集済み: Matt J 2018 年 2 月 14 日
result = sum(diff(array,1,1)==-1 ,1)
  3 件のコメント
Matt J
Matt J 2018 年 2 月 14 日
In that case,
result = sum( diff(array,1,1)==-1 ,2)
Abhishek Varghese
Abhishek Varghese 2018 年 2 月 14 日
編集済み: Abhishek Varghese 2018 年 2 月 14 日
Related Question:
Hey Matt, still currently optimising my code. Would love further help.
Considering that I have the adjacency matrix:
adj = [0 1 1 1
1 0 0 1
1 0 0 1
1 1 1 0];
and a binary matrix:
array = randi([0 1],4,10)
where the columns are each node in the network, and the rows for the state of the network at each time step. To clarify, if node 1 is '1' at time step 2, it would be like
array(2,1) = 1
What would I do, to create a vector of values that satisfied the same condition as my initial question, and also satisfy the condition of not having any infected neighbours in the same time step??
EDIT: An infection is considered a 1, no infection a 0
EDIT2: I have decided that perhaps its best to create another question. Please find the question here:
To receive credit for the answer! Cheers -Abhishek.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by