Identify rows of a matrix, which contain 0's, where there are 1's in an array.
3 ビュー (過去 30 日間)
古いコメントを表示
FSM = [0 1 0 1 1 1 0 0 0 0 0 0;
0 1 0 1 0 0 1 1 0 0 0 0;
0 1 0 1 0 0 0 0 1 1 0 0;
1 0 0 0 0 0 0 0 0 0 0 0;
1 1 1 1 0 0 0 0 0 0 0 1;
0 1 0 1 0 0 0 1 0 0 0 0;
0 1 0 1 0 0 0 0 0 1 0 0;
0 1 0 1 0 0 0 0 0 0 1 0];
O1 = [0 0 0 0 1 1 0 0 0 0 0 0];
O2 = [0 0 0 0 0 0 1 1 0 0 0 0];
O3 = [0 0 0 0 0 0 0 0 1 1 0 0];
O4 = [1 0 0 0 0 0 0 0 0 0 0 0];
O5 = [1 1 1 1 0 0 0 0 0 0 0 0];
O6 = [0 0 1 0 0 0 0 1 0 0 0 0];
O7 = [0 0 0 0 0 0 0 0 0 1 0 0];
O8 = [0 0 0 0 0 0 0 0 0 0 1 0];
I need to find the locations of the 1's in the O arrays, if there is any rows in the FSM matrix, where there are 0's in ALL of these places, that row returns a 0. However, if there is a 1 in any of these locations, that row returns a 1.
In the case of O1, the response would be [1 0 0 0 0 0 0 0], because there are 0's in the 5th AND 6th column of every row, other than the first.
I have several more arrays O2-O20, which contain various combinations of 0's and 1's
0 件のコメント
採用された回答
the cyclist
2023 年 12 月 16 日
I'm not quite certain this algorithm does what you want, since you only gave one example of the correct output, but I think so.
FSM = [0 1 0 1 1 1 0 0 0 0 0 0;
0 1 0 1 0 0 1 1 0 0 0 0;
0 1 0 1 0 0 0 0 1 1 0 0;
1 0 0 0 0 0 0 0 0 0 0 0;
1 1 1 1 0 0 0 0 0 0 0 1;
0 1 0 1 0 0 0 1 0 0 0 0;
0 1 0 1 0 0 0 0 0 1 0 0;
0 1 0 1 0 0 0 0 0 0 1 0];
O1 = [0 0 0 0 1 1 0 0 0 0 0 0];
% Result for O1
out1 = any(FSM(:,logical(O1)),2)'
2 件のコメント
the cyclist
2023 年 12 月 16 日
Please carefully consider @DGM's answer as well. It is generally a terrible idea to use dynamically named variables.
その他の回答 (1 件)
DGM
2023 年 12 月 16 日
編集済み: DGM
2023 年 12 月 16 日
Putting indices in the variable names only makes everything worse.
FSM = [0 1 0 1 1 1 0 0 0 0 0 0;
0 1 0 1 0 0 1 1 0 0 0 0;
0 1 0 1 0 0 0 0 1 1 0 0;
1 0 0 0 0 0 0 0 0 0 0 0;
1 1 1 1 0 0 0 0 0 0 0 1;
0 1 0 1 0 0 0 1 0 0 0 0;
0 1 0 1 0 0 0 0 0 1 0 0;
0 1 0 1 0 0 0 0 0 0 1 0];
% don't create piles of index-named variables
allO = [0 0 0 0 1 1 0 0 0 0 0 0;
0 0 0 0 0 0 1 1 0 0 0 0;
0 0 0 0 0 0 0 0 1 1 0 0;
1 0 0 0 0 0 0 0 0 0 0 0;
1 1 1 1 0 0 0 0 0 0 0 0;
0 0 1 0 0 0 0 1 0 0 0 0;
0 0 0 0 0 0 0 0 0 1 0 0;
0 0 0 0 0 0 0 0 0 0 1 0];
% permute
allO = permute(allO,[3 2 1]);
% process
output = permute(any(FSM & allO,2),[3 1 2])
Each row of the output array corresponds to the rows in allO. For example, output(1,:) is the example you gave for O1.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!