Find an outline to the valued data in a matrix of zeros and values

2 ビュー (過去 30 日間)
H
H 2022 年 2 月 3 日
コメント済み: H 2022 年 2 月 3 日
Hello,
I have matrix of data points that I basically need to distinguish a boundary between the numbers above zero and the zero.
for example-
0 2 2 0 0 0
0 0 2 1 2 0
0 2 1 1 2 0
0 0 2 1 2 0
Where I want to draw a line along all of the 2s (note these values are not the same in the actual matrix so I can't just say where x=2).
The end goal would be to say anything to the right of the right line is NaN, anything to the left of the left line is also NaN, leaving only the middle values intact.
usually I would just turn zero to NaN and create a mask that way, but there are some zeros in the center of the matrix that I do still need.
I might be going about it wrong and there is likely a very simple solution which I have over complicated in my head.
I am not asking for a full code, just maybe some ideas and helpful functions that could do this.
Thank you!

採用された回答

KSSV
KSSV 2022 年 2 月 3 日
REad about bwlabel.
I = [0 2 2 0 0 0
0 0 2 1 2 0
0 2 1 1 2 0
0 0 2 1 2 0];
L = bwlabel(I)
L = 4×6
0 1 1 0 0 0 0 0 1 1 1 0 0 1 1 1 1 0 0 0 1 1 1 0
  4 件のコメント
KSSV
KSSV 2022 年 2 月 3 日
r1 = [0 1 1 0 0 0] ;
%
strfind(r1,[0 1])
strfind(r1,[1 0])
% Or
find(diff(r1) == 1)
find(diff(r1) == -1)
H
H 2022 年 2 月 3 日
Thank you, this helps until I have zeros in the middle of my 1's in the matrix-
0 1 1 0 0 0
0 0 1 1 1 0
0 1 1 0 1 0
0 0 1 1 1 0
I will need to find a way to only include those on the most left/right side of the matrix. Thank you for your help.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by